2011-11-28 88 views
0

這是我的輸入文件..Sed則工作在一個系統上,但不能在其他

[[email protected] scripts]# cat ip6hdr.txt | xargs -n4 
6000 0000 005C 3320 
2001 0000 0000 0000 
0000 0000 0000 0100 
2001 0000 0000 0000 
0000 0000 0000 0200 

我想要的文件的第一行的最後兩個數字變化,即2000

我想這個..

cat ip6hdr.txt | xargs -n4 | sed '1,1s/\([0-9]*\) \([0-9]*\) \([0-9]*\) \([0-9][0-9]\)\([0-9][0-9]\).*/\1 \2 \3 \400 /' 

以前它在Ubuntu上工作的罰款,現在不工作在Fedora在bash腳本

我沒有理由爲什麼它在一個系統上,而不是其他一個..

[[email protected] scripts]# sed --version 
GNU sed version 4.1.5 
Copyright (C) 2003 Free Software Foundation, Inc. 
This is free software; see the source for copying conditions. There is NO 
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, 
to the extent permitted by law. 

如果可能的話建議我一些替代..

+1

檢查您的sed版本,即'sed --version'。另外爲什麼複雜的表達式,爲什麼不'sed'1s /..$/ 00 /''?祝你好運。 – shellter

+0

你的問題是什麼?什麼是sed版本? – thiton

+0

@shellter感謝和+1這個簡單的.. –

回答

2

爲什麼複雜的東西?

$ cat File 
6000 0000 005C 3320 
6000 0000 005C 3320 

$ sed '1s/..$/00/;' File 
6000 0000 005C 3300 
6000 0000 005C 3320 
+0

感謝和+1這個簡單的n短的方法 –

0

呦你應該使用[0-9a-fA-F]而不是[0-9]

+0

順便說一句,你爲什麼使用如此複雜的sed?爲什麼不用'sed -e'1 s/[0-9a-fA-F] {2} $/20 /''來代替(我的觀點是使用'$'將它貼到行尾)? – 2011-11-28 13:37:46

0

很可能您錯過了-e來表明您的sed表達式,並且Ubuntu sed更新更寬容。更簡單的表達可能會更好一些:

.... | sed -e '1s/[0-9][0-9]$/00/' 
+0

即使是Sun3'sed'也不需要'-e'。我只在複製/粘貼解決方案時使用它(差不多);-)祝大家好運! – shellter

相關問題