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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Grep or Tail in shell script Moxy Shell Programming and Scripting 3 08-03-2008 10:36 PM
tail | grep lagging badly WasabiVengeance Shell Programming and Scripting 3 04-22-2008 07:53 PM
tail, grep and cut sylaan Shell Programming and Scripting 7 03-04-2008 02:41 AM
Help with tail /grep needed Felix2511 UNIX for Dummies Questions & Answers 4 05-17-2007 04:22 PM
Constantly updating log files (tail -f? grep? awk?) nortonloaf UNIX for Dummies Questions & Answers 0 12-03-2006 11:20 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-22-2009
sdilucca's Avatar
sdilucca sdilucca is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 17
tail | grep

The program that is running on my machine generates log files. I want to be able to know the number of lines that contain "FT" in the most recent log file. I wrote the following, but it always returns zero. And I know the count is not zero. Any ideas?

ls -rt *.log | tail -n 1 | grep -c FT
  #2 (permalink)  
Old 01-22-2009
slant-40 slant-40 is offline
Registered User
  
 

Join Date: Apr 2007
Location: West Babylon NY 11704
Posts: 10
you need to assign ls-rt *.log | tail -n 1 to a variable, then grep that.
add | wc -l to the end of it to get the count


a=
a=`ls -rt *.log | tail -n 1`
cat $a | grep "FT" | wc -l
  #3 (permalink)  
Old 01-22-2009
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,807

Code:
grep -c FT  $(ls -rt *.log | tail -n 1 )

  #4 (permalink)  
Old 01-22-2009
Rhije Rhije is offline
Registered User
  
 

Join Date: Dec 2008
Posts: 103
Just so I have something to work with, could you give me a few file names, and the contents of those files? or samples? I like to test my scripts before giving them as answers >_<

-- Ignore the above.. apparently the ninja unix users beat me to it :P

Last edited by Rhije; 01-22-2009 at 12:13 PM.. Reason: The ninjas won :(
  #5 (permalink)  
Old 01-22-2009
manas_ranjan's Avatar
manas_ranjan manas_ranjan is offline
Registered User
  
 

Join Date: Jul 2007
Location: Amsterdam
Posts: 177
use
find with xarg and wc utility
  #6 (permalink)  
Old 01-22-2009
drack drack is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 6
grep -e "FT" /path/to/log/dir/*.log | wc -l
  #7 (permalink)  
Old 01-22-2009
sdilucca's Avatar
sdilucca sdilucca is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 17
thanks guys. the following worked for me:

egrep -c FT `ls -rt *.log | tail -n 1`
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:22 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0