If I run the command cat file | grep pattern, I get many lines of output. How do you concatenate all lines into one line, effectively replacing each "\n" with "\" " (end with " followed by space)?
cat file | grep pattern | xargs sed s/\n/ /g
isn't working for me.
sedscript in single-quotes so that Bash doesn't mess with it (sincesed s/\n/ /gcallssedwith two arguments, namelys/n/and/g); (2) since you want the output ofcat file | grep patternto be the input tosed, not the arguments tosed, you need to eliminatexargs; and (3) there's no need forcathere, sincegrepcan take a filename as its second argument. So, you should have triedgrep pattern file | sed 's/\n/ /g'. (In this case it wouldn't have worked, for reasons given at the above link, but now you know for the future.)