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

后端 未结 21 2052
没有蜡笔的小新
没有蜡笔的小新 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:35

    In the case where I needed to combine two lines (for easier processing), but allow the data past the specific, I found this to be useful

    data.txt

    string1=x
    string2=y
    string3
    string4
    
    cat data.txt | nawk '$0 ~ /string1=/ { printf "%s ", $0; getline; printf "%s\n", $0; getline } { print }' > converted_data.txt
    

    output then looks like:

    converted_data.txt

    string1=x string2=y
    string3
    string4
    

提交回复
热议问题