sed如何搭配陣列來使用? - Linux

By Valerie
at 2011-01-27T00:14
at 2011-01-27T00:14
Table of Contents
假設檔案array.txt內容為
array={"Tom","Mary","Jason","Brown","Jason","Smith","Lora","Cook","Bill",
"May","Lily","Ivy","Nick","Michael","James","Mark","Steve","Jay","Morris",
"Tim"}
執行
cat array.txt | sed -e 's/array={\([^{]*\)}/\1/g' | sed -e "s/\"/'/g" |
awk '{ print "array={"$0"}" }'
結果
array={'Tom','Mary','Jason','Brown','Jason','Smith','Lora','Cook','Bill',
'May','Lily','Ivy','Niko','Michael','James','Mark','Steve','Jay','Morris',
'Tim'}
Is this what you are looking for?
※ 引述《Arim (Arim5566)》之銘言:
: 想請教一下
: 如果我目前有一個陣列
: array={"Tom","Mary","Jason"....}
: 如果有一個檔案內容包含這些字串
: 我想利用sed並且讓''取代掉符合陣列裏面的這些字串
: 但是直接用陣列的話sed會出錯(無窮迴圈)
: 當然這個陣列還滿大的,大概30個到40個
: 如果搭配參數-e的話要寫滿長的@@
: 不知道有沒有較好的方法?
: 謝謝各位板友
--
Tags:
Linux
All Comments

By Kama
at 2011-01-28T04:48
at 2011-01-28T04:48

By Xanthe
at 2011-01-29T18:58
at 2011-01-29T18:58
Related Posts
ls搜尋特定日期之後的指令?

By Edward Lewis
at 2011-01-26T18:17
at 2011-01-26T18:17
Apache2 virtualhost 設定一問

By Caroline
at 2011-01-26T11:18
at 2011-01-26T11:18
請問 RAID 出錯時

By Tom
at 2011-01-26T11:07
at 2011-01-26T11:07
OpenSuse11.1 顯示問題

By Joe
at 2011-01-26T01:45
at 2011-01-26T01:45
ubuntu 10.4 的 xdialog 安裝?

By Dorothy
at 2011-01-26T00:01
at 2011-01-26T00:01