如何从命令输出的第二列?

编程入门 行业动态 更新时间:2024-10-20 20:37:15
本文介绍了如何从命令输出的第二列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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

更多推荐

如何从命令输出的第二列?

本文发布于:2023-11-02 14:36:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1552670.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:命令

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!