Regular expression AWK print inside brackets

4

look, inside my.txt file has the following description:

Flags: X - disabled, E - established

 0 E name="peer1_cymru" instance=default remote-address=38.xx.xx.xx
     remote-as=65555 tcp-md5-key="WUf4f8" nexthop-choice=default
     multihop=yes route-reflect=no hold-time=3m ttl=default
     in-filter=CYMRU-IN out-filter=CYMRU-OUT address-families=ip,ipv6
     update-source=ether1 default-originate=never remove-private-as=no
     as-override=no passive=no use-bfd=no remote-id=xx.xx.xx.xx
     local-address=xx.xx.xx.xx uptime=3h32m11s prefix-count=90668
     updates-sent=0 updates-received=90668 withdrawn-sent=0
     withdrawn-received=0 remote-hold-time=3h used-hold-time=3m
     used-keepalive-time=1m refresh-capability=yes as4-capability=yes
 state=established

I need the linux terminal using awk which is what I know to get only the prefix-count = 90668 item. You would need the output of the command to be the same: [90668] How to proceed?

    
asked by anonymous 07.07.2017 / 17:46

2 answers

4

Try using this with the input you receive:

'awk 'match($0, /prefix-count=(.*)/) {
print substr($0, RSTART, RLENGTH)

Explanation:

'awk 'match($0, - Start awk and start the RegEx part with memory space 0, where the input will be inserted.

/prefix-count=(.*)/ - This delimits that RegEx will catch anything after the prefix-count = sequence until the end of the line.

print substr($0, RSTART, RLENGTH) - This will print with what RegEx returns, from start to end of match     

07.07.2017 / 18:03
1

You can use this command:

awk -F = '/90668$/{print $NF}' arquivo

The -F option specifies that "=" is a field separator! awk looks in the file for the default value / $ 90668 / $ (final) server character to indicate that this value is at the end of the line! print $NF is to print the last field! It could have been that way too!

awk -F = '/8$/{print $NF}'

File 90668 that would have the same result! in the case of that question itself

    
19.10.2018 / 16:46