Awk

Simple string manipulations (splits/replaces) with awk

2020-06-17

For personal reference: Lately, I’ve been doing loads of CSV processing on the terminal with lots of string replacing/splitting. There are probably better (shorter) ways to do this but I’ve been leaning on awk a lot recently. Some examples. One-line separator replace: $ echo "1,2,3,4,5" | awk '{gsub(/,/," ");print}' 1 2 3 4 5 # Then I can use it with something like: for v in $(echo "1,2,3,4,5" | awk '{gsub(/,/," ");print}'); do echo "val=$v"; done val=1 val=2 val=3 val=4 val=5 # Another separator: $ echo "1|2|3|4|5" | awk '{gsub(/|/,",");print}' 1,2,3,4,5 # Join multiple lines with a separator.

Awk · Commandline · Split · String

1 minute