参见英文答案 >
Escaping separator within double quotes,in awk3个
我在用
我在用
awk '{ printf "%s",$3 }'
从空格分隔的行中提取一些字段.当我引用字段时,我得到部分结果.请问有谁提出解决方案吗?
解决方法
这实际上非常困难.我想出了以下awk脚本,它手动拆分行并将所有字段存储在一个数组中.
{ s = $0 i = 0 split("",a) while ((m = match(s,/"[^"]*"/)) > 0) { # Add all unquoted fields before this field n = split(substr(s,1,m - 1),t) for (j = 1; j <= n; j++) a[++i] = t[j] # Add this quoted field a[++i] = substr(s,RSTART + 1,RLENGTH - 2) s = substr(s,RSTART + RLENGTH) if (i >= 3) # We can stop once we have field 3 break } # Process the remaining unquoted fields after the last quoted field n = split(s,t) for (j = 1; j <= n; j++) a[++i] = t[j] print a[3] }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。