Reputation: 9
I am trying to get 3 separate single line commands to run one after the other, but am unable to get this to work if they are all in the same shell.sh file.
awk 'Command #1 1' input.txt > output.txt
awk 'Command #2 1' input.txt > output.txt
awk 'Command #3 1' input.txt > output.txt
Above is an example of what I will have in shell.sh, and I am only able to achieve this using 3 separate files, when I need these to all work in a single file.
In my example I want a single input file to have 3 commands run against it to produce a single output file.
I am not sure if I am able to combine using >>
, |
, or &&
, but all tries have given poor results.
Upvotes: 0
Views: 40
Reputation: 189749
Your attempt is overwriting the output file from each previous command, so it will appear as if only the last command succeeded.
If you want to run three Awk scripts in succession, you are looking for a pipeline.
awk 'Command #1 1' input.txt |
awk 'Command #2 1' |
awk 'Command #3 1' > output.txt
But of course, you probably want to combine them into a single script.
awk 'Command #1
Command #2
Command #3 1' input.txt> output.txt
Unfortunately, your question is too general to provide actual specific advice on whether this is feasible and useful.
Upvotes: 1
Reputation: 174816
You need to use the output redirection operator >>
awk 'Script #1 1' input.txt > output.txt
awk 'Script #2 1' input.txt >> output.txt
awk 'Script #3 1' input.txt >> output.txt
Upvotes: 2