我的命令的输出是一样的东西:
My command's output is something like:
1540 "A B" 6 "C" 119 "D"第一列始终是一个数字,后面加一个空格,然后一个双引号字符串。
The first column is always a number, followed by a space, then a double-quoted string.
我的目的是为了只得到第二列,如:
My purpose is to get the second column only, like:
"A B" "C" "D"我打算用< some_command> | AWK'{$打印2}来做到这一点。但问题是,在第二列的一些值包含空格(S),这恰好是对 AWK 默认的分隔符来分隔字段。因此,输出搞砸了:
I intended to use <some_command> | awk '{print $2}' to accomplish this. But the question is, some values in the second column contain space(s), which happens to be the default delimiter for awk to separate the fields. Therefore, the output is messed up:
"A "C" "D"我如何获得第二列的值(与配对的引号)干净?
How do I get the second column's value (with paired quotes) cleanly?
推荐答案或者使用SED&放大器;正则表达式。
Or use sed & regex.
<some_command> | sed 's/^.* \(".*"$\)/\1/'更多推荐
如何从命令输出的第二列?
发布评论