I have a users.txt file in the format:
User:CityID
Carl:0212
Syd:0312
Rick:9323
and a city.txt file in the format
Anaheim:0212
San Jose:0312
I need to replace every CityID in the users.txt with the city name from the city.txt file. How can I achieve this using sed and awk?
I can get the column of CityID's using awk using:
awk -F$'\:' '{print $2}'< users.txt
but how do it replace them with the corresponding city name?
Thank you.
awk '...' < file, you lose the ability for awk to populate the often-usefulFILENAMEvariable. Just let awk open the file itselfawk '...' file.