What's new
  • 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!

Some "grep" help.

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
 
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
 
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.
 
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
 
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
Thread starter Title Forum Replies Date
C I want to learn and would appreciate some help. Other Discussions 15

Similar threads

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

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