The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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
how can i pick the latest log file as per below mail2sant Shell Programming and Scripting 4 04-05-2009 01:14 AM
Read the latest file wereyou UNIX for Dummies Questions & Answers 3 02-10-2008 12:12 AM
Getting latest file from ftp arunavlp UNIX for Dummies Questions & Answers 3 02-08-2008 10:19 AM
get latest file via ftp command alx Post Here to Contact Site Administrators and Moderators 2 01-26-2006 11:44 AM
How to Grab the latest file n9ninchd UNIX for Dummies Questions & Answers 1 05-10-2001 04:31 PM

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

Join Date: Aug 2001
Posts: 79
get latest file

i have the following in my directory x:

3 files with the word "LIST" inside the files
2 files without the word "LIST"
1 folder (sudirectory)

i want to get the filename of the latest file (timestamp) with the word "LIST".

by the way the script and the list of files are in seperate folders.

i tried using:

ls -t | xargs grep -l "LIST" | head -1

but this only works if the script and file is within the same directory.

that's all folks :P
  #2 (permalink)  
Old 07-04-2003
mysth mysth is offline
Registered User
  
 

Join Date: Aug 2002
Location: Germany
Posts: 13
How about using "find"?

I don't know why exactly u want the newest of these files.
But find has some time-comparisson, maybe that'll help.
  #3 (permalink)  
Old 07-05-2003
oombera's Avatar
oombera oombera is offline Forum Advisor  
Registered User
  
 

Join Date: Aug 2002
Location: Cleveland, OH
Posts: 804
Try this:

find . -name "*" -print | xargs grep -l "Kevin" | xargs ls -lt | head -n 1
  #4 (permalink)  
Old 07-07-2003
inquirer's Avatar
inquirer inquirer is offline
Registered User
  
 

Join Date: Aug 2001
Posts: 79
yup bingo!

occasionally, users creates a file containing data using different file (for backtracking purpose). i want the script to automatically detect the latest file. and if that file contains the word LIST then that is the file i am looking for.

you are right oombera... but i have already used:

find . -name -type f -exec grep -l "LIST" {} \; | xargs ls -lt | head -n 1

it works the same. thanks for the inputs.
  #5 (permalink)  
Old 04-02-2009
vpraveena vpraveena is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 7
Command we tried using to grep ERROR from lastest 1 log files from 5 logs files available in that particular directory is:
grep ERROR 'ls -ltr | tail -1'

but this command is not working.. for me its saying.. cannot open DistributeImageFilesToTarget_10_dataLocations_PhillipinesDataLocations.xml.log

if i give ls -lrt for all the files in that diretory

-------r-- 1 egdevbb intdev 5022 Apr 2 05:13 DistributeDataFilesToTarget_4_dataLocations_ChinaDataLocations.xml.log
-------r-- 1 egdevbb intdev 1672 Apr 2 05:14 DistributeImageFilesToTarget_14_dataLocations_WHQDataLocations.xml.log
-------r-- 1 egdevbb intdev 7480 Apr 2 05:15 DistributeImageFilesToTarget_60_dataLocations_IndonesiaDataLocations.xml.log
-------r-- 1 egdevbb intdev 2113 Apr 2 05:34 DistributeImageFilesToTarget_8_dataLocations_MalaysiaDataLocations.xml.log
-------r-- 1 egdevbb intdev 2107 Apr 2 05:39 DistributeImageFilesToTarget_10_dataLocations_PhillipinesDataLocations.xml.log
Sponsored Links
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 05:31 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