Merging two greps outputs into one file

30 viewsLinux
0

here are the accompanying two charges:

grep ‘substring1’ file1.txt > outfile.txt

grep ‘substring2’ file2.txt > outfile.txt

I might want to combine the two greps, and think of all to outfile.txt as one charge. How might such summon resemble?

Answered question
0

You can easily combine both commands in a row, like:

grep ‘substring1’ file1.txt > outfile.txt ; grep ‘substring2’ file2.txt >> outfile.txt

The “;” separate both commands, the second command will be executed after the first has finished.

The “>>” means you append the output to the already existing file. (if the file does not exists, there will be no difference to “>”)

You can use this simple pattern for many different tasks.

Answered question