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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Awk help

Status
Not open for further replies.

millhouze

Technical User
Joined
Dec 5, 2006
Messages
1
Location
US
I have a file of a list of vehicles.

I have sorted them in ABC order and numbered the lines. How can I import this sort back into the original file?

I want a list with the numbered field added to the original file. The original file is not in ABC order.

EX:
(original file)
Chevy
Acura
Ford
Honda

(what I have with the command: sort -d cars | awk '{print NR, $0 }'
)
1 Acura
2 Chevy
3 Ford
4 Honda

(desired result)

2 Chevy
1 Acura
3 Ford
4 Honda

The command I used to get this so far is
sort -d cars | awk '{print NR, $0 }'

 
Try...

awk '{print NR, $0}' cars|sort -d -k2|awk '{print NR, $0}'|sort -n -k2|awk '{print $1,$3}'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top