My input is in TSV format:
C1
r1
r2
r3
C2
r1
r3
Desired output is:
C1 r1
r2
r3
C2 r1
r3
So, basically what I want is printing value of column 1 in next line, is it possible using Linux command?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityWith GNU sed:
$ sed -i.bak '/^[^[:blank:]]/{N;s/\n[[:blank:]]\+//;}' file
C1r1
r2
r3
C2r1
r3
Possible solution is with awk
:
awk '$1 ~ /C/ { p = 1; save = $1; } $1 !~ /C/ { if (p) { x = save $1; print x; p = 0; } else { print $0; } }' input
Result:
C1r1
r2
r3
C2r1
r3