While read line, awk $line with multiple delimiters While read line, awk $line with multiple delimiters unix unix

While read line, awk $line with multiple delimiters


The problem isn't with the value of FS it's this line as pointed to by the error:

f = "Alignments_" $5 ".sam"        print > f

You have two statements on one line so either separate them with a ; or a newline:

f = "Alignments_" $5 ".sam"; print > f

Or:

f = "Alignments_" $5 ".sam"print > f

As full one liner:

awk -F '[:\t]' 'FNR==NR{n[$1];next}$5 in n{print > ("Alignments_"$5".sam")}'

Or as a script file i.e script.awk:

BEGIN {    FS="[:\t]" }# read the list of numbers in Tile_Number_ListFNR == NR {    num[$1]    next}# process each line of the .BAM file# any lines with an "unknown" $5 will be ignored$5 in num {    f = "Alignments_" $5 ".sam"            print > f}

To run in this form awk -f script.awk Tile_Number_List.txt little.sam.

Edit:

The character - is used to represent input from stdin instead of a file with many *nix tools.

command | awk -f script.awk Tile_Number_List.txt -