It happens that you have a list and you’d like to combine multiple lines in one.
For example, a list like this one:
1 2 3 4 5 6 7 8 9 10 |
Mark Smith London Sarah Ruffle Glasgow Paul Thompson Liverpool .... |
And have something like that:
1 2 3 |
Mark - Smith - London Sarah - Ruffle - Glasgow Paul - Thompson - Liverpool |
How to achieve it?
Use this command:
1 |
sed 'N;N;s/\n/ - /g' list.txt |
Use one extra “N” for every line you want to merge. It’s like (N-1). So, if you want to merge 3 lines like in this example, you need 2 N’s. If you’d like to merge 2 lines, you just need 1 N, and so.
Happy merging 🙂