I need to move the contents of every second line up to the line above such that line2's data is alongside line1's, either comma or space separated works.
Input:
line1
line2
line3
line4
Output:
line1 line2
line3 line4
I've been doing it in vim with a simple recording but vim seems to crash when I tell it to do it 100 000 times... I'm thinking maybe sed would be a good alternative but not sure how to do what I want or maybe there's a better option?
Each line only contains 1 numerical value, I just have a million lines...
If I understand correctly, you have:
line1
line2
line3
line4
...
and you want:
line1<SEP>line2
line3<SEP>line4
then you can do it easily with (g)awk
like this:
awk 'NR % 2 == 1 { o=$0 ; next } { print o "<sep>" $0 }' INPUTFILE
Update: if the number of lines is odd, the above will omit the last line (as Martin Stettner pointed out) so this will not:
awk 'NR % 2 == 1 { o=$0 ; next } { print o "<sep>" $0 } END { if ( NR % 2 == 1 ) { print o } }' INPUTFILE
HTH