last line from grep resullt


Login or Register to Reply

 
Thread Tools Search this Thread
# 1  
Old 08-21-2007
last line from grep resullt

Hi,

I have a grep command returns more than 20 lines. I need to display the last line of the grep result that i get.
Can someone please help me with this ?

Thanks,
Sateesh
# 2  
Old 08-21-2007
CPU & Memory

Hello,
You can just redirect that output to sed and do something like this--

Your grep command | sed -n 20p

Thanks
Namish
# 4  
Old 08-21-2007
last line from the list of search patterns

Code:
awk '/result/ { save=$0 }END{ print save }' filename

# 5  
Old 01-28-2009
I needed to get the local IP of devices getting their addresses from DHCP by mac address.

Unfortunately, the file was long and devises had multiple IPs. Figuring that the last instance of the IP was the current IP I used cat, grep, tail, sed and cut in one line.

I am sure there is a better way to do this but at least it works.

cat /var/lib/dhcp/dhcpd.leases | grep 00:04:f2:12:05:90 -B5 | tail -6 | sed -n '1p' | cut -d' ' -f2

Hope this helps.
# 6  
Old 01-28-2009
As far as I know, there's not option to grep for 'only return last line'.
As ajcannon said; piping the output into tail -1 is probably your best bet.
Login or Register to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Grep -q not works with multiples grep in same line mierdatuti Shell Programming and Scripting 1 07-24-2018 07:39 AM
Sed/grep: check if line exists, if not add line? f77hack Shell Programming and Scripting 4 02-19-2018 12:36 PM
Grep with special chars line by line FelipeAd UNIX for Dummies Questions & Answers 2 05-15-2014 02:53 PM
Piping grep into awk, read the next line using grep Paul Moghadam UNIX for Dummies Questions & Answers 2 12-09-2013 11:58 PM
How to Grep than scan line below grep pattern umarsatti Shell Programming and Scripting 14 10-04-2013 02:30 PM
sed command to grep multiple pattern present in single line and delete that line vivek d r Shell Programming and Scripting 14 05-14-2013 08:07 AM
Grep a line kpsanjay Shell Programming and Scripting 4 12-12-2012 08:08 AM
Grep a new line? syalala Shell Programming and Scripting 23 11-22-2012 02:55 PM
Grep the word from pattern line and update in subsequent lines till next pattern line reached rbalaj16 Shell Programming and Scripting 5 06-18-2012 04:39 AM
How to grep the line with error where keyword in next line is known. manishdivs Shell Programming and Scripting 4 09-16-2011 10:21 AM
Sed or Grep to delete line containing patter plus extra line rocketman88 Shell Programming and Scripting 2 06-30-2010 06:59 AM
cat file1 read line-per-line then grep -A 15 lines down in fileb irongeekio Shell Programming and Scripting 6 01-28-2009 05:30 AM
Grep or other ways to output line above and/or below searched line sammac UNIX for Dummies Questions & Answers 2 07-24-2008 02:28 AM
GREP and Retrieve Line by Line maxmave Shell Programming and Scripting 2 06-03-2008 11:45 AM
grep the line only if next line matches pbsrinivas Shell Programming and Scripting 11 07-10-2007 08:51 AM