10 January 2022

sed

sed -n '5p' file.txt

sed '10,$' file.txt

sed '10,20' file.txt

What if we supply several files as arguments?

`

sed 's/old/new' file.txt

sed 's/old/new/g' file.txt

sed -f foo.sed file.txt

Note Many UNIX filter have an -i "in place" option. It will ovrewrite the original file. Use this with extreme caution only in a script you have carefully tested.

awk

This is great for data occurring in columns.

awk '{print $1}' file.txt

awk '$2 > 100 {print $0 }' file.txt

NF:  number of field
NR:  number of record

Putting text in output

printf