Answer the question
In order to leave comments, you need to log in
How to bite a substring from a string?
I am writing a shell script. it searches the logs for the lines I need, then I need to bite the substring I need from the line into the file.
here is the line:
May 31 04:12:10 SSCK01 dhcpd[16691]: [ID 988538 local7.notice] [tid:30] NTCE DHCPOP(101) Protocol: DHCPDiscover from STRING-K01 PON 1/1/02/01:12.1.1 (chAddr=00:13:77:6d:44:6b) via 81.91.202.1.
STRING-K01 PON 1/1/02/01:12.1.1
grep -E -o "\b[STRING-]+[X00,K01-99]+" "+[PON]+" "+[1/1/01-09/01-09/:01-64.1.1]\b"
Answer the question
In order to leave comments, you need to log in
if " STRING-" and " PON " are defining then you can do this:
$ awk -F" STRING-| PON " '{print "STRING-"$2" PON "$3 }' | awk '{print $1" "$2" "$3}' fileIn >> fileOut
cat your_log | perl -e 'while(<>){ if ($_ =~/.*from\s+(STRING.*)\s+\(chAddr/){ print $1."\n"; }}'
cat your_log | grep -E -o 'STRING-K\d{2}\s+PON\s+\d\/\d\/\d{2}\/\d{2}:\d{2}\.\d\.\d'
cat your_log | grep -E -o 'STRING-K\d{2}\s+PON\s+\d\/\d\/\d{2}\/\d{2}:\d{1,2}\.\d\.\d'
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question