使用awk从一行中提取值 [英] Use awk to extract value from a line

查看:164
本文介绍了使用awk从一行中提取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在文件中有这两行:

<first-value system-property="unique.setting.limit">3</first-value>
<second-value-limit>50000</second-value-limit>

我想使用awk或sed将以下内容作为输出:

where I'd like to get the following as output using awk or sed:

3    
50000

使用此sed命令无法按我希望的那样工作,我怀疑这是由于行条目中存在引号和定界符引起的.

Using this sed command does not work as I had hoped, and I suspect this is due to the presence of the quotes and delimiters in my line entry.

sed -n '/WORD1/,/WORD2/p' /path/to/file

如何从文件中提取所需的值?

How can I extract the values I want from the file?

推荐答案

awk -F'[<>]' '{print $3}' input.txt

input.txt:

input.txt:

<first-value system-property="unique.setting.limit">3</first-value>
<second-value-limit>50000</second-value-limit>

输出:

3
50000

这篇关于使用awk从一行中提取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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