It All Makes Sense Now

The blog of Mats Gefvert.

sed and awk Reference

Posted 10/10/2019 in Reference

Argument Description
 
awk '{print $1}' Print 1st word from lines separated by space
awk -F: '{print $1}' Print 1st word from lines separated by colons
 
sed -n Don't display input lines in output
sed '5d' Delete line number 5
sed '5,10d' Delete lines 5-10
sed '5,$d' Delete lines from 5 until end-of-file
sed -n '5~2p' Print every other line from the 5th line
 
sed -n '/pattern/p' Print lines matching a regex pattern
sed '/pattern/d' Delete lines matching a regex pattern
sed 's/my/your/g' Substitute all (-g) "my" with "your"
sed 's/my/your/2' Substitute the 2nd (-g) "my" with "your"
sed 's/my/your/gp' Substitute all and print lines
sed -n '/CREATE TABLE/=' Match and print line numbers

 

Bonus - purge all removed packages on a debian system:

dpkg -l | awk '/^rc/{print $2}' | sudo xargs apt-get -y purge

Add a comment

Please log in to post a comment. (It's quick and painless!)

Comments