- 论坛徽章:
- 0
|
如何替换特定列中的字符?
原帖由 "hp_unix" 发表:
那个截出特定域,替换以后再合并,我本来也是这样做的,
请问,不产生那些中间文件,来实现行吗?
It seems that, if I don't quote __code__ , the script cannot run....?
One line version:
- perl -e 'while(<>){chomp; split;@_[3] =~ s/0/1/g; $r=join " ",@_ ;print "$r\n"}' FILENAME
复制代码
Multi line version
- #!/usr/bin/perl
- #c4.pl
- while(<>)
- {
- chomp;
- split;
- @_[3] =~ s/0/1/g;
- $r=join " ",@_ ;
- print "$r\n"
- }
复制代码
./c4.pl FILENAME
RESULT:
before
- cat origin
- 1111 aaaa bbbbb 11111000011 2222
- 113 aaaa bbbbb 1110789011 0000
- 11111 aaaa bbbbb 11112380011 2112
- 11111 aaaa bbbbb 115013786 2222
复制代码
after
- perl -e 'while(<>) { chomp; split; @_[3] =~ s/0/1/g; $r=join " ",@_ ; print "$r\n" }' origin
- 1111 aaaa bbbbb 11111111111 2222
- 113 aaaa bbbbb 1111789111 0000
- 11111 aaaa bbbbb 11112381111 2112
- 11111 aaaa bbbbb 115113786 2222
复制代码 |
|