Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String chop

Status
Not open for further replies.

ranjit

Technical User
Apr 14, 2000
131
GB
How would I achieve the desired result below using awk. I wish to remove all characters from the second "-" onwards:

Input file:
tqharvc -d EDB_PRODUCTION -T 4
tqhrrpvc -d EDB_PRODUCTION2 -T R1

Desired result:
tqharvc -d EDB_PRODUCTION
tqhrrpvc -d EDB_PRODUCTION2

Thanks
 
A sed way:
sed 's!-[^-]*$!!' /path/to/input >output

An awk way:
awk '{sub(/-[^-]*$/,"");print}' /path/to/input >output

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
OOps, missread the OP.
Either:
[tt]sed 's!-[^-]*!!2'[/tt]
Or:
[tt]awk -F- '{print $1"-"$2}'[/tt]

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top