Dup Goto 📝

Basics

PT2/lang/awk 07-31 13:46:48
To Pop
16 lines, 91 words, 523 chars Monday 2023-07-31 13:46:48

$0 $1 etc

$0 is the whole line, $1 is the first column, $2 the second, etc.

Shift

There is no shift in awk. So you need to be a little creative.

The example here is to turn a two column, whitespace delimited table into a markdown table.

awk '{ printf("| %s | ",$1); for(i=2;i<=NF;i++) printf("%s ",$i); print " |"; }'

though this does not respect whitespace. In the case of the above, sed does a better job:

sed -e 's/^\s*\(\w*\)\s\s*\(.*\)$/| \1 | \2 |/'