移除字串的標點符號 - Linux

By Steve
at 2011-04-10T09:55
at 2011-04-10T09:55
Table of Contents
※ 引述《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"
--
: 設計內容:
: $ 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"
--
Tags:
Linux
All Comments

By Christine
at 2011-04-12T20:21
at 2011-04-12T20:21

By Valerie
at 2011-04-15T08:00
at 2011-04-15T08:00
Related Posts
sed用法 插入

By Frederic
at 2011-04-09T14:44
at 2011-04-09T14:44
想學習虛擬化技術

By Regina
at 2011-04-09T13:44
at 2011-04-09T13:44
VMWare Player做一個NAT

By Franklin
at 2011-04-09T13:00
at 2011-04-09T13:00
移除字串的標點符號

By Rosalind
at 2011-04-09T10:24
at 2011-04-09T10:24
移除字串的標點符號

By Carol
at 2011-04-09T01:48
at 2011-04-09T01:48