Hi I'm trying to filter a column in a PAF file with the AWK command and write it to a new file:
awk '$12>=20 {print $0}' /PATH/FILE.paf > /OUT/PATH/FITLERED_FILE.paf
This command makes sure the 12th column has a value of at least 20 and then prints the entire contents of the file - with the filtered column - to a new file.
This works for one file but I have 90+ I need to filter through. I tried using a for loop:
for i in /PATH/TO/FILES/*_mapped.paf; do awk '$12>=20 {print $0 > "awk_{}.out"}' $i; done
Which didn't work. And then I tried using a pipe command:
cat /Users/rimo/Desktop/Pat_Assemblies/flye_mapped.txt | parallel "awk '{$12>=20 print $0}' /Users/rimo/Desktop/Pat_Assemblies/Assemblies_Flye/{} > awk_{}"
Which also didn't work. I think the problem I am having is format-based but I would appreciate it if someone could steer me in the right direction!
gawk
on some systems, justawk
on most Linuxes except recent Ubuntu and maybe some others). $\endgroup$gawk
? No need to install it if you don't, it would just make some things easier if you already have it. $\endgroup$gawk
but I could install it if it's easier! What would you suggest as an alternative? $\endgroup$gawk
here. I was mistakenly thinking you wanted to edit the original file which is made easier by gawk (you can usegawk -i inplace
) and gawk won't choke if you have too many open files, but all you need to avoid that is to close the file handle after writing (see the last command in my answer), so you really don't need to worry. Just use the default awk. $\endgroup$