In a text document I want to concatenate every other line with the next. I guess sed is the thing to use? How would this be done?
sed operates by performing the following cycle on each lines of input: first, sed reads one line from the input stream, removes any trailing newline, and places it in the pattern space. Then commands are executed; […]. Add a newline to the pattern space, then append the next line of input to the pattern space.
In the two commands above, we passed two options to the paste command: -s and -d. The paste command can merge lines from multiple input files. By default, it merges lines in a way that entries in the first column belong to the first file, those in the second column are for the second file, and so on.
Method # 1 – Using echo & Printf The simplest way to append multiple lines to a file is to use the echo and printf command. Let us start with echo. Echo is a command used to output a string or multiple strings as arguments.
This is easiest using paste
:
paste -s -d' \n' input.txt
Although there's a Famous Sed One-Liner (38) to emulate this as in potong's answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With