如何从命令输出的第二列? [英] How to get the second column from command output?

查看:173
本文介绍了如何从命令输出的第二列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的命令的输出是一样的东西:

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/'

这篇关于如何从命令输出的第二列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆