sed的一個問題 - Linux
By Callum
at 2018-10-22T22:08
at 2018-10-22T22:08
Table of Contents
我手邊有一個Archlinux pacman安裝清單如下 :
----------------------------------------------------------------
#install.txt
atom #(see: C1. Configure Atom editor)
code #(see: C4. Configure vscode that like atom editor)
wget
p7zip
networkmanager
network-manager-applet #(attach to GUI setting)
gnome-nettool #(GUI network manager)
chromium
rsync
# (rsync is a good tool for backup on the local and the remote,
# It can implement copy and exclude some files or directories:
----------------------------------------------------------------
我要使用sed正規劃處理把#註解清除
查了一下sed的用法 寫個shell如下 :
----------------------------------------------------------------
#install.sh
pacman_cmd="pacman -S "
install_cmd=$(sed -e "s/#.*//" -e "s/^/${pacman_cmd}/" $1)
echo -e "\e[1;32m${install_cmd}\e[0m"
----------------------------------------------------------------
最後echo那段是顯示sed之後結果
執行的指令為 :
----------------------------------------------------------------
sh install.sh install.txt
----------------------------------------------------------------
期望的輸出如下 :
----------------------------------------------------------------
pacman -S atom
pacman -S code
pacman -S wget
pacman -S p7zip
pacman -S networkmanager
pacman -S network-manager-applet
pacman -S gnome-nettool
pacman -S chromium
pacman -S rsync
----------------------------------------------------------------
但實際的結果如下 :
----------------------------------------------------------------
pacman -S atom
pacman -S code
pacman -S wget
pacman -S p7zip
pacman -S networkmanager
pacman -S network-manager-applet
pacman -S gnome-nettool
pacman -S chromium
pacman -S rsync
pacman -S
pacman -S
----------------------------------------------------------------
多了2個空的pacman -S
我知道是最後兩行的#沒被消掉
但是sed應該有把它消掉呀QQ
其他都正確
到這邊就不會處理了orz
還請板上高手幫忙 謝謝!
--
我老婆-子瑜,不服出來灣阿
https://imgur.com/sCghzuF
https://imgur.com/JvAE0Qu
https://imgur.com/k9PCODr
https://imgur.com/CZmFmeq
https://imgur.com/S7FgYgF
--
----------------------------------------------------------------
#install.txt
atom #(see: C1. Configure Atom editor)
code #(see: C4. Configure vscode that like atom editor)
wget
p7zip
networkmanager
network-manager-applet #(attach to GUI setting)
gnome-nettool #(GUI network manager)
chromium
rsync
# (rsync is a good tool for backup on the local and the remote,
# It can implement copy and exclude some files or directories:
----------------------------------------------------------------
我要使用sed正規劃處理把#註解清除
查了一下sed的用法 寫個shell如下 :
----------------------------------------------------------------
#install.sh
pacman_cmd="pacman -S "
install_cmd=$(sed -e "s/#.*//" -e "s/^/${pacman_cmd}/" $1)
echo -e "\e[1;32m${install_cmd}\e[0m"
----------------------------------------------------------------
最後echo那段是顯示sed之後結果
執行的指令為 :
----------------------------------------------------------------
sh install.sh install.txt
----------------------------------------------------------------
期望的輸出如下 :
----------------------------------------------------------------
pacman -S atom
pacman -S code
pacman -S wget
pacman -S p7zip
pacman -S networkmanager
pacman -S network-manager-applet
pacman -S gnome-nettool
pacman -S chromium
pacman -S rsync
----------------------------------------------------------------
但實際的結果如下 :
----------------------------------------------------------------
pacman -S atom
pacman -S code
pacman -S wget
pacman -S p7zip
pacman -S networkmanager
pacman -S network-manager-applet
pacman -S gnome-nettool
pacman -S chromium
pacman -S rsync
pacman -S
pacman -S
----------------------------------------------------------------
多了2個空的pacman -S
我知道是最後兩行的#沒被消掉
但是sed應該有把它消掉呀QQ
其他都正確
到這邊就不會處理了orz
還請板上高手幫忙 謝謝!
--
我老婆-子瑜,不服出來灣阿
https://imgur.com/sCghzuF
https://imgur.com/JvAE0Qu
https://imgur.com/k9PCODr
https://imgur.com/CZmFmeq
https://imgur.com/S7FgYgF
--
Tags:
Linux
All Comments
By Caroline
at 2018-10-24T17:38
at 2018-10-24T17:38
By Connor
at 2018-10-29T08:01
at 2018-10-29T08:01
By Charlotte
at 2018-10-31T09:35
at 2018-10-31T09:35
By Hedwig
at 2018-11-01T02:14
at 2018-11-01T02:14
By Charlie
at 2018-11-02T10:55
at 2018-11-02T10:55
By Andy
at 2018-11-03T01:42
at 2018-11-03T01:42
By Kumar
at 2018-11-03T06:59
at 2018-11-03T06:59
By Heather
at 2018-11-04T22:44
at 2018-11-04T22:44
By Frederic
at 2018-11-09T20:20
at 2018-11-09T20:20
By Hedda
at 2018-11-14T11:25
at 2018-11-14T11:25
By Bennie
at 2018-11-17T05:23
at 2018-11-17T05:23
Related Posts
linux sever網路驅動問題
By Harry
at 2018-10-22T20:09
at 2018-10-22T20:09
Ubuntu有的程式點開啟/另存會卡住
By Suhail Hany
at 2018-10-22T04:23
at 2018-10-22T04:23
不同軟體音量異常互相影響
By Tracy
at 2018-10-20T16:09
at 2018-10-20T16:09
thinkpad trackpoint 小紅點速度很慢
By Edward Lewis
at 2018-10-19T21:19
at 2018-10-19T21:19
https://www.sslforfree.com/出現錯誤
By Wallis
at 2018-10-19T09:38
at 2018-10-19T09:38