3

I'm using awk to do many-to-one filtering i.e. read several .csv files and, using a condition, filter records from those files into another csv file. The command is

awk -F, '{if($1=="OPTSTK"&&$13>0)print > "stockoptions.csv";}' fo1.csv fo2.csv

This command does the job for me except that when I run this command for a new set of csv files (say fo3.csv and fo4.csv) the output from the previous command execution gets overwritten. Is there a way to append the output from the subsequent executions to the output from the first execution of the command?

1 Answer 1

7

Yes, use >> instead of >.

For example:

awk -F, '$1 == "OPTSTK" && $13 > 0 { print >> "stockoptions.csv" }' fo1.csv fo2.csv

Or, let the shell do the redirection and cut the length of the awk command:

awk -F, '$1 == "OPTSTK" && $13 > 0' fo1.csv fo2.csv >>"stockoptions.csv"
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .