From Schmid.wiki
Jump to: navigation, search

Examples

print first word of each input line

$ awk '{print $1}'

special ls:

$ ls | awk 'BEGIN{x=0}{printf("file #%2d: \"%s\"\n", ++x, $1);}'

a little sine(swine?)-table:

$ awk 'BEGIN{for(x=0;x<3.142*2;x+=3.142/10) printf("svin(%.1f) = % .3f\n", x, sin(x));}'
  • convert a file with this format:
 #Sekretær Kirsten Hyltoft 23

 Svend Hubert Ølgod: username00 (DOS-newline)
 Åge Gunnar Erik Ækelsen: username01 (DOS-newline)

  • to this format:
 #Sekretær Kirsten Hyltoft 23

 svend.oelgod: username00
 aage.aekelsen: username01

$ awk '{if(NR>1 && NF>3) {print tolower($1) "." tolower($(NF-2)) " " $(NF-1);} else print $0}' $1 | \
        sed -e 's/æ/ae/g' -e 's/å/aa/g' -e 's/ø/oe/g' -e 's/ü/ue/g' -e 's/ö/oe/g' >$2


References