Use tr '
' ' '
to translate all newline characters to spaces:
$ grep pattern file | tr '
' ' '
Note: grep
reads files, cat
concatenates files. Don't cat file | grep
!
Edit:
tr
can only handle single character translations. You could use awk
to change the output record separator like:
$ grep pattern file | awk '{print}' ORS='" '
This would transform:
one
two
three
to:
one" two" three"
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…