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

后端 未结 21 2160
没有蜡笔的小新
没有蜡笔的小新 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条回答
  •  盖世英雄少女心
    2020-11-22 15:44

    Another solutions using vim (just for reference).

    Solution 1:

    Open file in vim vim filename, then execute command :% normal Jj

    This command is very easy to understand:

    • % : for all the lines,
    • normal : execute normal command
    • Jj : execute Join command, then jump to below line

    After that, save the file and exit with :wq

    Solution 2:

    Execute the command in shell, vim -c ":% normal Jj" filename, then save the file and exit with :wq.

提交回复
热议问题