3

I have a text file,of 100 lines,i need to move line 40 to line 39(refer to position) How to do this with sed? I tried

sed '40 m 39' file

and

sed '40,39m' file

but give me error. Thanks

elbarna
  • 12,695

2 Answers2

3

With GNU sed:

seq 1 43 | sed -e '39{h;d};40{p;g}' | tail -n 8

Output:

36
37
38
40
39
41
42
43
Cyrus
  • 12,309
1

Try:

$ sed -e '39N;s/\(.*\)\n\(.*\)/\2\
\1/' file
cuonglm
  • 153,898