How to merge every two lines into one from the command line?

后端 未结 21 2054
没有蜡笔的小新
没有蜡笔的小新 2020-11-22 15:14

I have a text file with the following format. The first line is the \"KEY\" and the second line is the \"VALUE\".

KEY 4048:1736 string
3
KEY 0:1772 string
1         


        
21条回答
  •  Happy的楠姐
    2020-11-22 15:48

    Simplest way is here:

    1. Remove even lines and write it in some temp file 1.
    2. Remove odd lines and write it in some temp file 2.
    3. Combine two files in one by using paste command with -d (means delete space)

    sed '0~2d' file > 1 && sed '1~2d' file > 2 && paste -d " " 1 2
    

提交回复
热议问题