The simplest way is to use paste
as follows:
paste - - < myFile
In this command, paste
reads the file from stdin and combines every two lines (that's what the two "-" are for) into a single line separated by a tab.
Domanda
I've got a file with numbers on odd lines and text on even lines like this:
123123
string A
456456
string B
789789
string C
I want to get it to this format (tab separated):
123123 string A
456456 string B
789789 string C
I tried to remove all newlines with
tr -s -d " " < myFile
then use sed
with
sed -i 's/[0-9]\s/' myFile
but without great success.
Can you help me get this done?
Soluzione
The simplest way is to use paste
as follows:
paste - - < myFile
In this command, paste
reads the file from stdin and combines every two lines (that's what the two "-" are for) into a single line separated by a tab.
Altri suggerimenti
Try:
sed '$!N;s/\n/\t/' inputfile
This would join the lines separated by a TAB character.
Example:
$ seq 10 | sed '$!N;s/\n/\t/'
1 2
3 4
5 6
7 8
9 10
Yo can try the following:
paste <(grep -E '^[[:digit:]]+' myFile) \
<(grep -E '^[[:alpha:]]+' myFile) \