I need join 2 lines into one in stdout - replace new line AND 4x space with one space but new line without space don't touchtcpdump -vvv ... -l | xyzthis is output:2014-06-06 AAA    BBB2014-06-06 CCC    DDDbut I need: 2014-06-06 AAA BBB2014-06-06 CCC DDD
Replace new line + 4x space to new line in stdout
bash;text processing;string
I thought of another way to do this that doesn't rely on paired lines but instead only a <space> character following a \newline character:sed ':n;N;s/\n  */ /;tn;P;D' That uses a sliding window of newline data and the test function to operate. The flow is like this:define the :next labelappend Next line in input to pattern spaces/elect a \newline character followed by 1 or more <space> characters and replace them with a single /<space>/test if last s/// was successful and, if so, branch to :next label, else...Print up to the first \newline character in pattern space and...Delete up to and including first \newline character in pattern space and restart cycle with remaining pattern space or with next line So, basically, all occurrences of \n [ ]* in input get squeezed into [ ]:sed ':n;N;s/\n  */ /;tn;P;D' <<\DATA2014-06-06 AAA    BBB2014-06-06 CCC    DDD2014-06-06 EEE2014-06-06 FFF    GGGDATAOUTPUT:2014-06-06 AAA BBB2014-06-06 CCC DDD2014-06-06 EEE2014-06-06 FFF GGGOLD:sed -n 'h;n;H;x;s/\n */ /p' <<\DATA2014-06-06 AAA    BBB2014-06-06 CCC    DDDDATAOUTPUT:2014-06-06 AAA BBB2014-06-06 CCC DDDI use 5 sed commands. overwrite hold space with pattern space...overwrite pattern space with the next line in inputappend pattern space to Hold space following an automatically inserted \newline characterexchange the contents of hold and pattern spacess/elect the first \newline character and any or *all following spaces then /replace the selection with a single space and /print the result.Though, now that I think about it, a simplified version of both mine and @Falsenames answers - which really is better than this one - would just be:sed 'N;s/\n */ /' <<\DATA2014-06-06 AAA    BBB2014-06-06 CCC    DDDDATA    OUTPUT:2014-06-06 AAA BBB2014-06-06 CCC DDD