bash awk 打印没有引号的值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14641020/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 04:25:02  来源:igfitidea点击:

awk print value without quote sign

linuxbashcentos

提问by Sokphak

I have this value

我有这个价值

option 'staticip' '5.5.5.1'

I want to print only 5.5.5.1without quote sign. I have use

我只想打印5.5.5.1没有引号。我用过

cat /etc/filename | grep staticip | awk '{print }'

but the result come with '5.5.5.1'

但结果是 '5.5.5.1'

回答by radical7

Or, you can use trto remove the offending characters:

或者,您可以使用tr删除违规字符:

cat /etc/filename | grep staticip | awk '{print }' | tr -d \'

回答by lc.

You can use awk's gsub()function to change the quotes to nothing.

您可以使用 awk 的gsub()函数将引号更改为空。

awk '{gsub(/'"'"'/, "", ); print }'

Note this is really gsub(/'/, "", $3). The ugliness comes from the need to glue quotes together.

注意这是真的gsub(/'/, "", $3)。丑陋来自需要将引号粘在一起。

回答by Steven Penny

awk '=="staticip" && 
5.5.5.1
=' FS="'"

Result

结果

##代码##

回答by spartygw

You could use awks substr function or pipe that to the cut command. I leave you to read the man page for awk substr.

您可以使用 awks substr 函数或将其通过管道传递给 cut 命令。我让您阅读 awk substr 的手册页。