How to switch/rotate every two lines with sed/awk?

前端 未结 4 632
时光取名叫无心
时光取名叫无心 2020-12-15 08:47

I have been doing this by hand and I just can\'t do it anymore-- I have thousands of lines and I think this is a job for sed or awk.

Essentially, we have a file lik

4条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-15 08:52

    First question:

    awk '{x = $0; getline; print; print x}' filename
    

    next question: sort by 2nd line

    paste - - < filename | sort -f -t $'\t' -k 2 | tr '\t' '\n'
    

    which outputs:

    dobroye utro!
    Good morning!
    annyonghaseyo
    hello
    watashi
    me
    

提交回复
热议问题