Awk and sed

From Notepedia
Jump to: navigation, search

AWK

http://www.thegeekstuff.com/2010/01/awk-introduction-tutorial-7-awk-print-examples/

AWK like GREP:

awk '/:/ { print $0 }' /etc/group

Print specific fields using " " white space as a delimiter:

awk '{print $2,$5;}' employee.txt

Print a specific field using ":" as a delimiter:

awk -F ":" '{print $4}' /etc/group

SED

Command and breakdown

sed -i '/vim/d' /etc/bash.bashrc"

-i deletes the file in place (requires GNU sed)

/<string>/d command deletes the line with the search string

s/2000/2012/g will search and replace 2000 with 2012


on OSX the above works with the -e switch:

sed -ie '/vim/d' /etc/bash.bashrc"