Unix one-liner to swap/transpose two lines in multiple text files?

后端 未结 8 1863
谎友^
谎友^ 2021-01-06 03:22

I wish to swap or transpose pairs of lines according to their line-numbers (e.g., switching the positions of lines 10 and 15) in multiple text files using a UNIX tool such a

8条回答
  •  萌比男神i
    2021-01-06 04:07

    With GNU awk:

    awk '
    FNR==NR {if(FNR==14) x=$0;if(FNR==26) y=$0;next} 
    FNR==14 {$0=y} FNR==26 {$0=x} {print}
    ' file file > file_with_swap
    

提交回复
热议问题