1

Could you please help me how to grep two strings (or the whole lines) from one file and write them on the same line in output file?

grep -e "string1 string2" inputfile > output.txt doesn't work

for one string it works:

grep -e "string1" inputfile > output.txt 

thx!

user3041107
  • 123
  • 2
  • 13

1 Answers1

1

Change your grep command like below,

grep -o 'string1\|string2' file | paste - - > out.txt

This writes string1 string2 in a single line on out.txt

Avinash Raj
  • 172,303
  • 28
  • 230
  • 274