jaapar
February 6, 2018, 2:24am
1
hi folks, looking for a way to view a file and get the output of bold strings below? Thanks.
20-AUG-2017 16:14:59 * (CONNECT_DATA=(SID=TST)(CID=(PROGRAM=)(HOST=__jdbc__)(USER=xxxx))) * (ADDRESS=(PROTOCOL=tcp)(HOST=144.55.11.55)(PORT=50622)) * establish * TST * 0
Hello jaapar,
Could you please try following and let me know if this helps you.
awk '{match($0,/HOST=[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/);if(substr($0,RSTART,RLENGTH)){print substr($0,RSTART,RLENGTH)}}' Input_file
Thanks,
R. Singh
1 Like
RudiC
February 6, 2018, 3:50am
3
If the only criterion were an IP address in dotted quad to follow the "HOST=" string, then RavinderSingh13's proposal would work fine, although it might be somewhat too cautious.
awk 'match($0,/HOST=[0-9.]+/) {print substr($0,RSTART,RLENGTH)}' file
HOST=144.55.11.55
would do the same. But there might be additional criteria, like it should be part of the ADDRESS section, or belong to the tcp PROTOCOL, or have a certain PORT set...?
1 Like
jaapar
February 6, 2018, 4:57am
4
ravindersingh13:
Hello jaapar,
Could you please try following and let me know if this helps you.
awk '{match($0,/HOST=[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/);if(substr($0,RSTART,RLENGTH)){print substr($0,RSTART,RLENGTH)}}' Input_file
Thanks,
R. Singh
This works like a charm. Thanks Singh!
---------- Post updated at 04:57 AM ---------- Previous update was at 04:56 AM ----------
rudic:
If the only criterion were an IP address in dotted quad to follow the "HOST=" string, then RavinderSingh13's proposal would work fine, although it might be somewhat too cautious.
awk 'match($0,/HOST=[0-9.]+/) {print substr($0,RSTART,RLENGTH)}' file
HOST=144.55.11.55
would do the same. But there might be additional criteria, like it should be part of the ADDRESS section, or belong to the tcp PROTOCOL, or have a certain PORT set...?
This works fine, thanks Rudy!!!
If you have this as a value in $var, you could also:-
echo $var | tr "()" "\n\n" | grep -E "^host="
It's a bit clunky, but might do the job you need.
Robin
1 Like