shell命令检索使用模式特定值 [英] Shell command to retrieve specific value using pattern

查看:96
本文介绍了shell命令检索使用模式特定值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含类似下面的数据文件。

I have a file which contains data like below.

appid=TestApp
version=1.0.1

我们要分析该文件并捕获分配到的appid字​​段的值。

We want to parse the file and capture the value assigned to appid field.

我与awk命令尝试如下

I have tried with awk command as below

awk '/appid=/{print $1}' filename.txt

但它输出整行

appid=TestApp 

但我们只需要

TestApp

请让我知道我可以用awk / grep的/ sed的shell命令实现这一点。

Please let me know how I can achieve this using awk/grep/sed shell commands.

推荐答案

您需要更改字段分隔符:

You need to change the field separator:

awk -F'=' '$1 ~ /appid/ {print $2}' filename.txt

或精确匹配

awk -F'=' '$1 == "appid" {print $2}' filename.txt

输出

TestApp

这篇关于shell命令检索使用模式特定值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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