Hands-on task
awk: join two files by key
There are two files with a shared key in the first field: /root/names.txt (id name) and /root/ages.txt (id age). Write an awk program in the file /root/join.awk (handy to do in the Editor tab above the terminal): it gets two such files — first id age, then id name — and prints lines name age in the order of the second file, only for ids that have both a name and an age. Run it with awk -f on ages.txt and names.txt and write the result to /root/joined.txt (ids in ascending order there). The program will also be tested on other files.
- awk
- join by key
- NR and FNR
- associative arrays
- next