![](/img/trans.png)
[英]How to compare two files, one has different fields and other is a c file, using shell script?
[英]print two different fields of files using
我有一个日志:
100.100.100.100 - - [08/Mar/2016:07:53:33 +0100] GET /rbt/Utils.do?receiverID=665135085&action=send_sms&senderID=22077&dtocRequest=n&smsText=Tu+PIN+es+95934&isPostMethod=n&subscriberID=665135085&useSameResForConsent=n&mode=WEB
我只需要显示两个字段。 日期和订户ID字段(仅数字)。
我正在尝试以下命令:
cut -d" " -f4,7 input.txt | awk -F"subscriberID=" '{print $2}' input.txt | cut -c0-9
我的输出:
665135085
要求的输出:
08/Mar/2016:07:53:33 +0100 665135085
请帮助。
这是sed
的工作:
sed -E 's/.*\[([^]]*)\].*subscriberID=([0-9]*).*/\1 \2/' input.txt
如果您有一个不支持“扩展的”正则表达式(由-E
标志启用)的怪异的sed
,则必须在每个打开和关闭括号之前添加一个\\
:
sed 's/.*\[\([^]]*\)\].*subscriberID=\([0-9]*\).*/\1 \2/' input.txt
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.