[英]Awk remove specific characters
I have command, which gives me output from telnet. 我有命令,这给了我telnet的输出。 Full output from telnet It looks like this:
telnet的完整输出如下所示:
telnet myserver.com 1234
Server, Name=MyServer, Age=123, Ver=1.23, ..., ..., ...
服务器,名称= MyServer,年龄= 123,版本= 1.23,...,...,...
This command should filter just the number after Age - "Age= 123 " which I want to filter: 此命令应仅过滤我要过滤的Age- “ Age = 123 ”之后的数字:
echo "\n" | nc myserver.com 1234 | (awk -F "=" '{print $3}')
Instead of 123 it gives me this output: 而不是123,它为我提供了以下输出:
123, Ver
123,Ver
Is there a way how to get just number after Age= 有没有办法在Age =之后获得数字 ?
?
It's just bad awk filtering parameter, but I tried some other ways with awk but this gave me almost best result... Thank you for any help. 这只是糟糕的awk过滤参数,但是我尝试了awk的其他方式,但这给了我几乎最好的结果...谢谢您的帮助。
Edit: I forgot, number after Age= is dynamic +1 every day... 编辑:我忘记了,Age =之后的数字每天是动态+1 ...
I'm not sure about the echo "\\n"
part but I think that this should do what you want: 我不确定
echo "\\n"
部分,但是我认为这应该可以完成您想要的操作:
nc myserver.com 1234 | awk -F "," '{ split($3, a, /=/); print a[2] }'
Instead of splitting into fields on the =
, I've done so on the ,
. 我没有在
=
上拆分字段,而是在,
。 The third field is then split into the array a
on the =
and the second half is printed. 然后将第三个字段拆分为
=
上的数组a
,并打印后半部分。
I also removed the ( )
around the invocation of awk, which was creating a subshell unnecessarily. 我还删除了awk调用周围的
( )
,它不必要地创建了一个子shell。
If you're confident about the response never varying containing =
or ,
in other places, you could simplify the awk expression further: 如果你自信的回应永远变化的含
=
或者,
在其他地方,你可以进一步简化了awk的表达式:
awk -F'[=,]' '{ print $5 }'
The bracket expression allows fields to be split on either =
or ,
, making the part you're interested in the fifth field. 方括号表达式允许在
=
或,
上拆分字段,从而使您对第五个字段感兴趣的部分。
You can run the awk command twice. 您可以运行awk命令两次。
awk -F "=" '{print $3}'|awk -F "," '{print $1}'
You can also use the cut command: 您还可以使用cut命令:
cut -d "=" -f 3|cut -d "," -f 1
echo "\n" | nc myserver.com 1234 | awk -F "," '{print substr($3,6)}'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.