亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

Chinaunix

標(biāo)題: sed 命令腳本求解! [打印本頁(yè)]

作者: chenbindream    時(shí)間: 2007-12-06 13:32
標(biāo)題: sed 命令腳本求解!
一個(gè)比較大的文件,約500M。求幾個(gè)sed腳本命令實(shí)現(xiàn)以下的功能:

1. 把這個(gè)文件的第1行到第10行,復(fù)制到第20行!☆愃苬i中的1,10co 20

2.   把這個(gè)文件的第1行到第10行,移動(dòng)到第20行!☆愃苬i中的1,10mo 20

3.   把這個(gè)文件的有ufs的行,復(fù)制兩行到有ufs行的后面!☆愃苬i中的yyp 再p

4.   把這個(gè)文件的有ufs的行,和接下來(lái)的行,做行交換。類似vi中的ddp.

如何實(shí)現(xiàn)?  謝謝。
作者: chenbindream    時(shí)間: 2007-12-06 15:09
沒(méi)人回答,自己頂一個(gè)! 


3. sed  '/ufs/{h;G;G}'  file > file.tmp
mv file.tmp file
作者: BLZer    時(shí)間: 2007-12-06 15:27
1):
sed '1,10H;20G'
2):
sed -n '1,10H;10{G};1,10!p'
4):
sed '/ufs/{N;s/\(.*\)\n\(.*\)/\2\n\1/};'
作者: ly5066113    時(shí)間: 2007-12-06 15:28
1、sed -e '1,10{1h;1!H;}' -e '20G' urfile
2、sed -n -e '1,10{1h;1!H;}' -e '11,${20G;p;}' urfile
4、sed '/ufs/{N;s/\(.*\)\n\(.*\)/\2\
\1/;}' urfile
作者: springwind426    時(shí)間: 2007-12-06 15:32
復(fù)制1到10到第20行
sed -i ':a;1,9N;1,9ba;10h;20{x;G}'
移動(dòng)1到10行到第20行
sed -i ':a;1,9N;1,9ba;10{x;d};30{x;G}'
有ufs的行,復(fù)制兩行
sed -i '/ufs/{N;s/^\([^\n]\+\)\n\(.*\)/\1\n&\n\2/}'
有ufs的行,交換
sed -i '/ufs/{N;s/^\([^\n]\+\)\n\(.*\)/\2\n\1/}'
作者: cjaizss    時(shí)間: 2007-12-06 15:51
1. 把這個(gè)文件的第1行到第10行,復(fù)制到第20行。 類似vi中的1,10co 20
sed -rn '1h;2,10H;20G;p'
2.   把這個(gè)文件的第1行到第10行,移動(dòng)到第20行。 類似vi中的1,10mo 20
sed -rn '1,10{1h;1!H;d};20G;p'
3.   把這個(gè)文件的有ufs的行,復(fù)制兩行到有ufs行的后面!☆愃苬i中的yyp 再p
sed -r '/ufs/{p;p};'
4.   把這個(gè)文件的有ufs的行,和接下來(lái)的行,做行交換。類似vi中的ddp.
sed -rn '/ufs/{h;n;p;s/^.*$//;x};p'

[ 本帖最后由 cjaizss 于 2007-12-6 16:05 編輯 ]
作者: chenbindream    時(shí)間: 2007-12-07 10:45
在Solaris 中實(shí)驗(yàn)如下:

root@application # cat file
Line one is 1
The second is line 2
That is the third line 3
the fourth is line 4
five line 5
Sixth is a line 6
This is seven Line 7
Right eigth line 8
That is ninth  Line 9
The  line is ten 10
last line is the last line 11

root@application # sed -e '2,5{2h;2!H}' -e '7G' file
Line one is 1
The second is line 2
That is the third line 3
the fourth is line 4
five line 5
Sixth is a line 6
This is seven Line 7
The second is line 2
That is the third line 3
the fourth is line 4
five line 5
Right eigth line 8
That is ninth  Line 9
The  line is ten 10
last line is the last line 11

成功,達(dá)到要求....

root@application # sed -n -e '2,5{2h;2!H}' -e '6,${7G;p}' file
Sixth is a line 6
This is seven Line 7
The second is line 2
That is the third line 3
the fourth is line 4
five line 5
Right eigth line 8
That is ninth  Line 9
The  line is ten 10
last line is the last line 11

缺少一行喲 ..... 沒(méi)有達(dá)到要求。

sed -e '2,5{2h;2!H}' -e '7G' file

sed -n -e '2,5{2h;2!H}' -e '6,${7G;p}' file 

各位大俠,能不能把這兩個(gè)命令行,做一下解釋說(shuō)明工作? 謝謝
作者: ly5066113    時(shí)間: 2007-12-07 10:49
原帖由 chenbindream 于 2007-12-7 10:45 發(fā)表
root@application # sed -n -e '2,5{2h;2!H}' -e '6,${7G;p}' file
Sixth is a line 6
This is seven Line 7
The second is line 2
That is the third line 3
the fourth is line 4
five line 5
Right eigth line 8
That is ninth  Line 9
The  line is ten 10
last line is the last line 11

缺少一行喲


缺哪一行?
作者: chenbindream    時(shí)間: 2007-12-07 10:52
Line one is 1 。
作者: ly5066113    時(shí)間: 2007-12-07 10:54
原帖由 chenbindream 于 2007-12-7 10:52 發(fā)表
Line one is 1 。


sed -n -e '2,5{2h;2!H}' -e '6,${7G;p}' file
從第二行才開(kāi)始復(fù)制,第一行當(dāng)然沒(méi)有。

sed -n -e '1,5{1h;1!H}' -e '6,${7G;p}' file
作者: chenbindream    時(shí)間: 2007-12-07 11:10
把這個(gè)文件的第3行到第5行,移動(dòng)到第7行。 類似vi中的3,5mo 7  如何實(shí)現(xiàn)呢???

大俠能不能做一下解釋說(shuō)明工作???
作者: ly5066113    時(shí)間: 2007-12-07 11:15
sed -n -e '3,5{3h;3!H;}' -e '7G;3,5!p'

詳情參見(jiàn):
http://www.72891.cn/viewthread.php?tid=336126




歡迎光臨 Chinaunix (http://www.72891.cn/) Powered by Discuz! X3.2