請教shellscript parse [ 1, 2 ] 中數字 - Linux

By Jacky
at 2011-10-19T05:59
at 2011-10-19T05:59
Table of Contents
※ 引述《ptthidebear (= =)》之銘言:
: 標題: [問題] 請教shellscript parse [ 1, 2 ] 中數字
: 時間: Mon Oct 17 10:04:40 2011
:
:
: Hi~ 各位板大先進大家好
:
: 小弟對於shell script 不是很熟悉
:
: 最近剛好碰到一個問題是 想要用shell script parse 字串
:
: "asdfwer [ 1234, 3456 ]" 中的 1234 和 3456 出來
:
: 並且加以比對看數字是不是一樣
:
: 當然希望最好是一行 command就可以解決...|||Orz
grep有問題,不用grep,一行指令如下: (Windows平台)
cat %filename% | cut -d[ -f2 | cut -d, -f1 | sed "s/ //g" > n1.txt & cat
%filename% | cut -d, -f2 | cut -d] -f1 | sed "s/ //g" > n2.txt & diff n1.txt
n2.txt && echo number1 is number2 || echo number1 is not number2
%filename% 請改成真正的檔名
把&拿掉, 其實是三行指令啦! ^^"
都用GNU的指令, 要弄到別的平台應該很容易修改吧!?
GnuWin32下載網址:
http://gnuwin32.sourceforge.net/packages.html
http://sourceforge.net/projects/gnuwin32/files/coreutils/5.3.0/coreutils-5.3.0.exe/download
(for cat,cut)
http://sourceforge.net/projects/gnuwin32/files/sed/4.2.1/sed-4.2.1-setup.exe/download
(for sed)
http://sourceforge.net/projects/gnuwin32/files/diffutils/2.8.7-1/diffutils-2.8.7-1.exe/download
(for diff)
如果不能隨便安裝主機, 只要複製bin資料夾出來即可使用.
把bin資料夾設定到Path環境變數, 或切換到bin資料夾執行指令.
(用絕對路徑執行指令當然一定可以)
:
:
: 不知道各位大大們對於這個問題有沒有什麼建議或是指教的
:
: 非常謝謝大家!!!
:
:
:
: --
: 標題: [問題] 請教shellscript parse [ 1, 2 ] 中數字
: 時間: Mon Oct 17 10:04:40 2011
:
:
: Hi~ 各位板大先進大家好
:
: 小弟對於shell script 不是很熟悉
:
: 最近剛好碰到一個問題是 想要用shell script parse 字串
:
: "asdfwer [ 1234, 3456 ]" 中的 1234 和 3456 出來
:
: 並且加以比對看數字是不是一樣
:
: 當然希望最好是一行 command就可以解決...|||Orz
grep有問題,不用grep,一行指令如下: (Windows平台)
cat %filename% | cut -d[ -f2 | cut -d, -f1 | sed "s/ //g" > n1.txt & cat
%filename% | cut -d, -f2 | cut -d] -f1 | sed "s/ //g" > n2.txt & diff n1.txt
n2.txt && echo number1 is number2 || echo number1 is not number2
%filename% 請改成真正的檔名
把&拿掉, 其實是三行指令啦! ^^"
都用GNU的指令, 要弄到別的平台應該很容易修改吧!?
GnuWin32下載網址:
http://gnuwin32.sourceforge.net/packages.html
http://sourceforge.net/projects/gnuwin32/files/coreutils/5.3.0/coreutils-5.3.0.exe/download
(for cat,cut)
http://sourceforge.net/projects/gnuwin32/files/sed/4.2.1/sed-4.2.1-setup.exe/download
(for sed)
http://sourceforge.net/projects/gnuwin32/files/diffutils/2.8.7-1/diffutils-2.8.7-1.exe/download
(for diff)
如果不能隨便安裝主機, 只要複製bin資料夾出來即可使用.
把bin資料夾設定到Path環境變數, 或切換到bin資料夾執行指令.
(用絕對路徑執行指令當然一定可以)
:
:
: 不知道各位大大們對於這個問題有沒有什麼建議或是指教的
:
: 非常謝謝大家!!!
:
:
:
: --
Tags:
Linux
All Comments

By Isabella
at 2011-10-23T22:47
at 2011-10-23T22:47
Related Posts
中數字

By Elvira
at 2011-10-19T05:02
at 2011-10-19T05:02
設定NIS時ypbind無法啟動

By David
at 2011-10-18T19:13
at 2011-10-18T19:13
linux要怎麼換語言阿??

By Ursula
at 2011-10-18T16:16
at 2011-10-18T16:16
OpenVPN redirect-gateway 問題

By Jacob
at 2011-10-18T15:43
at 2011-10-18T15:43
中數字

By George
at 2011-10-18T14:18
at 2011-10-18T14:18