I am doing grep and sed and I get 2 lines of a file that I am interested in. How can I get these lines in a single line ending with the new line character?
Now I am getting:
pattern1
pattern2
I would like to get pattern1 pattern2 \n
I am doing grep and sed and I get 2 lines of a file that I am interested in. How can I get these lines in a single line ending with the new line character?
I would like to get |
||||
That says: "read a line from stdin (the first a bash-specific technique:
ref: http://www.gnu.org/software/bash/manual/bashref.html#index-mapfile |
|||||||||
|
I'll put three versions different methods in a row
And there are many more. |
|||||||||
|
you can do it using shell script or in command-line, just put the output of the command in a variable then
|
|||||||||||||||||||||
|
With
|
|||
|
A simple way, pipe output to
This only works with small ouput, because it's limited by maximum characters per command line. The largest value depends on system, you can get this value using |
||||
|
IFS will be happy to eat it if you want. |
|||
|
wrap your sed/grep in backticks when your original command was:
your new command would be:
Doesn't get the spaces in between lines, but you can always tack on another sed pipe:
|
|||||
|
printf %s\\n pattern1 pattern2 | sed '$!N;s/\n/ /'
– val0x00ff yesterday