Re: [問題] 移除字串的標點符號
※ 引述《dyoll (lloyd huang)》之銘言:
: ※ 引述《antontw (三十個扮上進青年之一)》之銘言:
: : 設計內容:
: : $ cat file.txt
: : 2000,"1,234,567","5,678",3000,10000,"1,300"
: : 1000,"1,121,234,567","4,321",3000,10000,"2,600"
: : 執行結果:
: : $ echo $(sed -e 's/$/#/' -e 's/"\([^"]*\)"/\n"\1"\n/g' file.txt | \
: : sed -e '/^"/s/[",]//g') | sed -e 's/ //g' -e 's/#/\n/g'
: : 2000,1234567,5678,3000,10000,1300
: : 1000,1121234567,4321,3000,10000,2600
: : 唔 ... 犧牲掉一個 # 了 ...
: Hi antontw
: 謝謝你,看了你的解法,讓我有了另外的想法,參考您的作法後改變如下
: $ cat file.txt | sed -e 's/$/END/' -e 's/"\([^"]*\)"/\n"\1"\n/g' | \
: sed -e '/^"/s/,//g' | sed -e :x -e 'N;s/\n//;/END/!tx;{s/END//}'
: 2000,"1234567","5678",3000,10000,"1300"
: 1000,"1121234567","4321",3000,10000,"2600"
我是用loop的方式去除""內的,
sed ':head
s/"\([0-9][0-9]*\),\([0-9][0-9,]*\)"/"\1\2"/g
# substite again if there are comma inside quotes
thead
# else, remove the quotes
s/"//g'
這樣應該會比較簡單一點
有的sed如果不支援註解的,要把#開頭那行拿掉才能執行
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 123.205.130.47
→
04/10 17:29, , 1F
04/10 17:29, 1F
推
04/11 01:22, , 2F
04/11 01:22, 2F
→
04/11 10:43, , 3F
04/11 10:43, 3F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 5 之 5 篇):