I have a file called "text.bz2" which contains a number of records which i want to process. I have a script which successfully processes all the data in a standard text file and outputs the results to a different "results.txt" file, but the command I'm currently running outputs all the results of the bz2 file to the command prompt (like cat does), creates the results.txt file - but it is empty.
This is the cammand I'm running:
bzip2 -dc text.bz2 | awk ... '
'
> results.txt
The format of the data in the decompressed bz2 file is:
field1=xxx;field2=xxx;field3=111222222;field4=xxx;field5=xxx
field1=xxx;field2=xxx;field3=111222222;field4=xxx;field5=xxx
field1=xxx;field2=xxx;field3=111222333;field4=xxx;field5=xxx
field1=xxx;field2=xxx;field3=111222444;field4=xxx;field5=xxx
field1=xxx;field2=xxx;field3=111222555;field4=xxx;field5=xxx
field1=xxx;field2=xxx;field3=111222555;field4=xxx;field5=xxx
field1=xxx;field2=xxx;field3=111222777;field4=xxx;field5=xxx
field1=xxx;field2=xxx;field3=111222888;field4=xxx;field5=xxx
and the output is exactly as expected, as below, but instead of the results being output to a text file, it's output to the command window:
111222333 111
111222444 111
111222555 111
111222777 222
111222888 111
What am i doing wrong with my bzip / redirection command?
Many thanks
Put the > file
at the end of the awk command, not on the line after it:
foo | awk 'script' > file
not
foo | awk 'script'
> file