简体   繁体   中英

print two different fields of files using

I have a LOG:

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

I need to display only two fields. Date and subscriberID field (only digits).

I am trying below commands:

cut -d" " -f4,7 input.txt | awk -F"subscriberID=" '{print $2}' input.txt | cut -c0-9

My output:

665135085

Required output:

08/Mar/2016:07:53:33 +0100 665135085

Kindly help.

This is a job for sed :

sed -E 's/.*\[([^]]*)\].*subscriberID=([0-9]*).*/\1 \2/' input.txt

If you have a weird sed that doesn't support "extended" regular expressions (enabled by the -E flag), you have to add a \\ before each opening and closing paren:

sed 's/.*\[\([^]]*\)\].*subscriberID=\([0-9]*\).*/\1 \2/' input.txt

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM