How can I use awk to join various fields, given that I don’t know how many of them I have? For example, given the input string
aaa/bbb/ccc/ddd/eee
I use -F'/' as delimiter, do some manipulation on aaa, bbb, ccc, ddd, eee (altering, removing…) and I want to join it back to print something line
AAA/bbb/ddd/e
Thanks
Ah, but you do know how many you have. Or you will soon, if you keep reading 🙂
Before giving you a record to process,
awkwill set theNFvariable to the number of fields in that record, and you can useforloops to process them (comments aren’t part of the script, I’ve just put them there to explain):This shows manipulation of the values, as well as insertion and deletion.