Tutorial by Examples: awk

Reading line by line awk '/^>/ {printf("%s%s\t",(N>0?"\n":""),$0);N++;next;} {printf("%s",$0);} END {printf("\n");}' < input.fa one can read this awk script as: if the current line ($0) starts like a fasta header (^>). Then we prin...
$ gunzip -c input.fastq.gz | awk '{printf("%s%s",$0,((NR+1)%4==1?"\n":"\t"));}' | head @IL31_4368:1:1:996:8507/2 TCCCTTACCCCCAAGCTCCATACCCTCCTAATGCCCACACCTCTTACCTTAGGA + FFCEFFFEEFFFFFFFEFFEFFFEFCFC<EEFEFFFCEFF<;EEFF=FEE?FCE @IL31_4368:1:1:996:21421/2...
If the program is short, you can include it in the command that runs awk: awk -F: '{print $1, $2}' /etc/passwd In this example, using command line switch -F: we advise awk to use : as input fields delimiter. Is is the same like awk 'BEGIN{FS=":"}{print $1,$2}' file Alternativelly, ...
AWK is string manipulation language, used largely in UNIX systems. The idea behind AWK was to create a versatile language to use when working on files, which wasn't too complex to understand. AWK has some other variants, but the main concept is the same, just with additional features. These other v...
I hope this example will help everyone to understand how awk internal variables like NR, FNR etc change when awk is processing two files. awk '{print "NR:",NR,"FNR:",FNR,"fname:",FILENAME,"Field1:",$1}' file1 file2 NR: 1 FNR: 1 fname: file1 Field1: f1d1 NR:...

Page 1 of 1