Lit*_*ode 5 shell-script text-processing cut
假设我有一个 CSV 文件:
"col1","col2","col3"
"col4","col5,subtext","col6
Run Code Online (Sandbox Code Playgroud)
我遇到的问题如下:
cut -d, -f1,2 test.txt
"coll1","col2"
"col4","col5
Run Code Online (Sandbox Code Playgroud)
所需的输出是:
"col1","col2"
"col4","col5,subtext"
Run Code Online (Sandbox Code Playgroud)
Perl 附带的 ParseWords 模块非常优雅地涵盖了这一点。下面举例。
$ perl -MText::ParseWords -nE '@a=quotewords ",",1,$_;say $a[0],",",$a[1]' <test.txt
"col1","col2"
"col4","col5,subtext"
$
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
707 次 |
最近记录: |