I have a rather convoluted script that I use to extract information from CSV files:
sed '1d' PeakTable.txt | awk -F ',' '!/Ladder/{ if ( $4 > 430 && $4 < 490 && $5 > 45 ) print $2, $5; else print $2, 0 }' | awk '{a[$1]+=$2}END{for(i in a){print i, a}}' | sed 's/\([A-z]\)\([1-9]\) /\10\2 /' | sort | awk '{if ($2 > 10) print $1, $2, 800 / $2; else print $0, 0}' | awk '{print "PCR_Plate", NR, $3, 1, "Deadpool" }' | sed '1 i\Source Well_Source Volume Destination_Well Destination' | sed 's/ /,/g' > output.txt
Here is the breakdown:
sed '1d' # delete first line
awk -F ',' '!/Ladder/{ if ( $4 > 430 && $4 < 490 && $5 > 45 ) print $2, $5; else print $2, 0 }' # Exclude rows including "Ladder" and selecting the ones with values between 430-490 in clumn 4; and greather than 45 in column 5.
awk '{a[$1]+=$2}END{for(i in a){print i, a}}' # collapsing rows with identical values in column 1
sed 's/\([A-z]\)\([1-9]\) /\10\2 /' | sort # adding 0 to single digits and sorting
awk '{if ($2 > 10) print $1, $2, 800 / $2; else print $0, 0}' # if column 2 > 10, divide 800 by value in column 2 and add it to the 3rd column. Otherwise print the line and add a 0 in 3rd column
awk '{print "PCR_Plate", NR, $3, 1, "Deadpool" }' # add constants to columns 1, 2 (consecutive numbers), value in column 3, 1, Deadpool
sed '1 i\Source Well_Source Volume Destination_Well Destination' # add headers
sed 's/ /,/g' # replace blank spaces with commas -CSV format
I would like to have one well structured awk
script handling the entire process. Any help will be greatly appreciated.
PS. I am attaching both the infile and outfiles.