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

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

    nawk '$0 ~ /string$/ {printf "%s ",$0; getline; printf "%s\n", $0}' filename
    

    This reads as

    $0 ~ /string$/  ## matches any lines that end with the word string
    printf          ## so print the first line without newline
    getline         ## get the next line
    printf "%s\n"   ## print the whole line and carriage return
    

提交回复
热议问题