I basically want to take the line that is under the word "LOAD" in filename1, and make it the second column in a new file, where the first column comes from filename2. (This is being done inside a loop, but I think that's irrelevant.)
So if I have
grep -A 1 LOAD filename1 >> temp
paste filename2 temp >> filename3
rm temp
Is there a way to do that in one command, with no temp file? Something like
grep -A 1 LOAD filename1 | paste filename2 "grep output" >> filename3
grep is very often used as a "filter" with other commands. It allows you to filter out useless information from the output of commands. To use grep as a filter, you must pipe the output of the command through grep . The symbol for pipe is " | ".
Stdout is processed by grep and stderr is printed to the terminal.
Conclusion: In Linux, for redirecting output to a file, utilize the ”>” and ”>>” redirection operators or the top command. Redirection allows you to save or redirect the output of a command in another file on your system. You can use it to save the outputs and use them later for different purposes.
You can use process substitution instead of using a temporary file:
paste filename2 <(grep -A 1 LOAD filename1) >> filename3
You can use '-' to represent the input from the pipe
grep -A 1 LOAD filename1.txt | paste filename2.txt - >> filename3.txt
grep -A 1 LOAD filename1.txt | paste filename2.txt /dev/stdin >> filename3.txt
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With