What's new

Some "grep" help.

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

octopus

Part of the Furniture
Hi

I need some suggestions...;)
I use
Code:
grep -E -m 1 "blabla"
to ensure only get first aswere in a command when get multiple answeres.
Now my question: if I want last answer and in multiple answeres, howe to accomplished that?


Thanks :D
Octopus
 

Martineau

Part of the Furniture
I use
Code:
grep -E -m 1 "blabla"
to ensure only get first aswere in a command when get multiple answeres.
Now my question: if I want last answer and in multiple answeres, howe to accomplished that?
In lieu of processing/reading the file in reverse..

I don't think grep alone will provide the solution, but using a single external utility try
Code:
awk '/blabla/ {LAST=$0} END {print LAST}'
or grep plus an additional external utility solution
Code:
grep "blabla" | tail -n 1
 

octopus

Part of the Furniture
In lieu of processing/reading the file in reverse..
Code:
grep "blabla" | tail -n 1
Thank you, this working fine. Tested awk couldn't get that working.
 

Martineau

Part of the Furniture
Tested awk couldn't get that working.
Works for me...
Code:
echo Blabla         >awktest.txt
echo Blabla_second >>awktest.txt
Code:
grep Blabla awktest.txt

Blabla
Blabla_second
Code:
awk '/Blabla/ {LAST=$0} END {print LAST}' awktest.txt

Blabla_second
even this manky code works...
Code:
cat awktest.txt | awk '/Blabla/ {LAST=$0} END {print LAST}'

Blabla_second
 

octopus

Part of the Furniture
Works for me...
Code:
echo Blabla         >awktest.txt
echo Blabla_second >>awktest.txt
Code:
grep Blabla awktest.txt
Blabla
Blabla_second
Code:
awk '/Blabla/ {LAST=$0} END {print LAST}' awktest.txt
Blabla_second
even this manky code works...
Code:
cat awktest.txt | awk '/Blabla/ {LAST=$0} END {print LAST}'
Blabla_second

Okay thanks
I get "awk" working also. Whis is preferred programming wise?
Code:
awk '/VERIFY OK: depth=0/ {LAST=$0} END {print LAST}' /tmp/vpnclient-1.log | cut -d ',' -f2 | cut -d "=" -f2
vpn63.prd.kista.ovpn.com
 

Similar threads

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top