how to grep for a word in a log file..


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to grep for a word in a log file..
# 1  
Old 10-15-2008
how to grep for a word in a log file..

Hi All,

I have a log file which is storing a backup time stamps information in it. (pasted below)

20081006210008 0 20081006211910
20081006222824 0 20081006224758
20081007210049 0 20081007212032
20081008210059 0 20081008212204
20081009210053 0 20081009212801
20081010210142 0 20081010212548
20081011210236 0 20081011212332
20081012210140 0 20081012212507
20081013210351 0 20081013212542
20081014210142 0 20081014212502

Now i would like to grep for last line and display... i know that we can do this using tail -1 |awk {print $1,$2,$3}.

Am using online script for collecting the backup information from all the systems and the problem here is that all the log file are not similar.. some would have spaces at end of the file... so when i do tail -1 it would not work for some of the systems.. and so would have other information at the end of the log file...

since the timestamps are available in all the logfiles... i would like to grep for last line which starts from 2008*.. and i dont know how do we grep for a word which start from 2008 and avoid the remainig when it dont have spaces.

file.log |grep 2008* |tail -1 ... guess this would not work..

How do we do this...?

Guru.. please help..
# 2  
Old 10-15-2008
Code:
grep ^2008 file.log | tail -n1

# 3  
Old 10-15-2008
Thank you... johnson..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script example to Grep matching word from file

Hi expert, Need help in shell script. a.txt file output is below i would like to grep 3 line and 1st column value which is admin\22226 only and not full line. i only know admin word as 22226 can come anything with admin\ in file. also after fetching it i would like to use this... (1 Reply)
Discussion started by: kuljeetpal
1 Replies

2. UNIX for Beginners Questions & Answers

How to Grep second word in config file using parameter?

Currently i am building one script to grep region records in the config file based on parameter and then i am creating a text file with that out put and i am reading the source file path in that out put file now i need to pass one more parameter like module based upon that it has to create a... (1 Reply)
Discussion started by: saranath
1 Replies

3. Shell Programming and Scripting

Grep the 5th and 6th position character of a word in a file

I am trying to find/grep the 5th and 6th position character (TX) of a word in a file. I tried to do grep "....TX" file The output gives me everything in the file with TX in it. I only need the output with the TX in the 5th and 6th position of the word. Any idea Example: test1 car... (5 Replies)
Discussion started by: e_mikey_2000
5 Replies

4. Shell Programming and Scripting

How can I just grep one instance of a word in the file

I want to grep some information out of the dmidecode but when I type dmidecode | grep Memory I get several instances of the word. Is there a way I can just choose which instance I want to display? (8 Replies)
Discussion started by: jcnewton13
8 Replies

5. Shell Programming and Scripting

Grep to isolate a text file line and Awk to select a word?

I am looking at using grep to locate the line in the text file and them use awk to select a word or words out of it. I know awk needs -v to allow a variable to be used, but also needs -F to allow the break up of the sentence and allow the location of separate variables. $line = grep "1:" File |... (8 Replies)
Discussion started by: Ironguru
8 Replies

6. Shell Programming and Scripting

grep part of word or Another word from a string

Hi all, FileOne family balance >>>>> 0 0 0 0 java.io.FileNotFoundException: Settings.xml (No such file or directory) at java.io.FileInputStream.open(Native Method) .. .... ..... ..... java.lang.NullPointerException ... ..... ...... Stacktrace: at... (2 Replies)
Discussion started by: linuxadmin
2 Replies

7. Shell Programming and Scripting

how to grep the max length word form a file?

Hi i have a requirement that is extract the max length word from a file ? plz reply (2 Replies)
Discussion started by: vankireddy
2 Replies

8. UNIX for Dummies Questions & Answers

Grep the word at the end of the file

I need to grep the word "hello" in each and every file. This word will be placed either at the end of the file or before the end of the file. Ex: file1: file2: afdsaf dsfalk fdsa weruoi sdaf erwqiuo fsdaf ... (5 Replies)
Discussion started by: sivakumar.rj
5 Replies

9. Shell Programming and Scripting

grep second word in a file

How do I match second word and then print that line to output For eg: My file has following text and I want to check if second word is n then I want to print entire line . xytxti8naclip y xytxt32bpsimple y xytxt32bpna n xytxti16nae y xysmps32bpp031_bst n... (7 Replies)
Discussion started by: pitagi
7 Replies

10. Shell Programming and Scripting

grep all records in a file and get a word count -perl

Hi, I have a file .. file.txt .. i need to get a total record count in the files into a $variable.. im using perl script thanks (4 Replies)
Discussion started by: meghana
4 Replies
Login or Register to Ask a Question