search latest version of log file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting search latest version of log file
# 8  
Old 09-29-2008
Quote:
Originally Posted by era
Code:
grep pattern $(ls -lrt | awk '{ file=$NF } END { print file }')

The value of $(command ...) is the output of command ...

If your shell doesn't support the $(...) syntax you will have to use `...` instead. Those are backticks (grave accents, ASCII 96) not regular straight quotes.


That works a treat - Thanks for your help.



FYI
The ls -ltr | tail -1 | cut -d " " -f10 doesnt work as the field separator is not unique - the length varies depending on the file size.
# 9  
Old 09-29-2008
The -l option for ls command is unnecessary :
Code:
ls -tr | tail -1

Jean-Pierre.
# 10  
Old 04-02-2009
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 -lrt | awk '{ file=$NF } END { print file }')
grep: can't 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
# 11  
Old 04-02-2009
(Note ls -one rather than ls -ell).

Code:
LATEST_FILENAME="`ls -1tr ????????_??.log 2>/dev/null | tail -1`"

if [ ! "${FILENAME}""X" = "X" ]
then
        grep <your pattern> "${LATEST_FILENAME}"
fi

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to Fetch latest version form a file?

Hi, I have a file where versions will be updated, i need to get latest/last updated version from that file. Could you please help? File looks like below - <versions> <version>R20180417.006</version> <version>R20180421.007</version> <version>R20180421.008</version> ... (5 Replies)
Discussion started by: schandra128
5 Replies

2. Shell Programming and Scripting

Search for latest Timestamp in file

Hi, I have a file which generate Timestamp in this format :- 20121012162354 20121114191610 20121210232808 20121216220002 20130106220002 20130127220001 20130203220001 20121012162354 20121114191610 20121210232808 20121216220002 20130106220002 20130127220001 20130203220001 (2 Replies)
Discussion started by: netdbaind
2 Replies

3. Shell Programming and Scripting

Help with finding the latest modified version of a file within directories

I am trying to look into multiple directories and pluck out the latest version of a specific file, regardless of where it sits within the directory structure. Ex: The file is a .xls file and could have a depth within the directory of anywhere from 1-5 Working directory - Folder1... (6 Replies)
Discussion started by: co21ss
6 Replies

4. AIX

Latest firmware version for P770

Dears i have a power7 P770 working in AIX 5.3 TL 11 with frimware AM730_066 is the AM730_066 frimware the latest one or not ? (6 Replies)
Discussion started by: thecobra151
6 Replies

5. Shell Programming and Scripting

Perl's buffered I/O is causing me to miss latest log file entries in log colorizer. How to fix?

I've been finding myself using a log file colorizer written in perl to reformat and colorize the output from many different programs. Mainly, however, I use it to make the output from "tail -f" commands more readable. The base perl script I use is based on "colorlogs.pl" available from the... (1 Reply)
Discussion started by: rcsteiner
1 Replies

6. Shell Programming and Scripting

search for latest file

Hi, In need to write a bash script which will be run periodically to check the files in a target directory. This receives files on an ad hoc basis and the script need to compare the time stamp of the latest file received with system time and write a message to the server log file if the time... (2 Replies)
Discussion started by: mark_s_g
2 Replies

7. BSD

latest version of bsd

Any body there ? What is latest BSD version ? (4 Replies)
Discussion started by: chilaka
4 Replies

8. Shell Programming and Scripting

Latest version of a file across the servers ..

:o How do I confirm that the script on one server is latest compare to other servers? Is there any script which can tell me the latest version of a file across the servers? Thanks, (2 Replies)
Discussion started by: Sandy
2 Replies

9. UNIX for Dummies Questions & Answers

What is the latest version of Unix?

I want to buy it (2 Replies)
Discussion started by: LANSTARR.COM
2 Replies

10. UNIX for Dummies Questions & Answers

Downloading vs buying latest version of os

I am currently taking a Unix programming class in school, I want ot know which is more efficient and quicker, downloading the os or buying the os (4 Replies)
Discussion started by: lavonte
4 Replies
Login or Register to Ask a Question