The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
reading from two files line by line windows Shell Programming and Scripting 2 08-09-2008 03:58 AM
reading ps command's output line by line s. murat Shell Programming and Scripting 5 05-22-2008 01:23 AM
reading text file line by line MizzGail Shell Programming and Scripting 6 04-14-2008 03:58 AM
reading line by line and grepping QueryMaster Shell Programming and Scripting 4 01-30-2008 02:12 PM
Reading line by line from a file tej.buch Shell Programming and Scripting 2 01-22-2006 11:50 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 10-09-2008
Registered User
 

Join Date: Sep 2007
Posts: 31
reading in the last line from grep

hi all,
from a shell (ksh) script, i am doing a grep which returns multiple lines. how do i read the last line returned into a variable ??


ta.
Reply With Quote
Forum Sponsor
  #2  
Old 10-09-2008
Registered User
 

Join Date: Apr 2008
Location: Calgary
Posts: 196
grep <pattern> <source> | tail -1
Reply With Quote
  #3  
Old 10-09-2008
Registered User
 

Join Date: Sep 2007
Posts: 31
hey thanks, how do i reuse the grep command output which i stored in a variable to get the last line ?? e.g

#!/bin/ksh
.
.
.
myVar=$(grep "errorPort" systemlog.log);
myLastLine=$($myVar | tail -1);


this doesnt seem to work. any suggestions ??
Reply With Quote
  #4  
Old 10-09-2008
vidyadhar85's Avatar
The Tutor
 

Join Date: Jun 2008
Location: INDIA
Posts: 537
try it in this way
echo "$myvar"|tail -1
Reply With Quote
  #5  
Old 10-09-2008
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 727
Code:
myVar=$(grep "errorPort" systemlog.log | tail -1);
Reply With Quote
  #6  
Old 10-09-2008
Registered User
 

Join Date: Oct 2008
Posts: 14
tail -1
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 01:55 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0