How to search in a log file?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to search in a log file?
# 1  
Old 01-07-2012
How to search in a log file?

Hey guys,

I'm still relatively new to Linux and everyday is a learning experience for me. Anyway, I have a question about searching inside a log file and didn't know what topic this would come under so posting it here as I am a Dummie lol!

Say I have a log file which consists of say, for example, 500,000 rows and I need to search that file for a specific error message - whats the best way of doing so ? Currently, if I need to look through the whole file I am using the 'more' command and then searching using the forward slash and entering what I want to look for - is there a more efficient way ?

Do any of you guys have any 'cheat sheets' of commands in more/vim for using !? One of the guys at work suggested using the 'Shift' key with certain keys but for the life of me I can't remember what ones.

My knowledge at the minute of Sed/Awk to attempt this is extremely limited so unfortunately can't use those utilities as yet to help.

- Jim
# 2  
Old 01-07-2012
man grep

simple example

Code:
grep foo bar.txt | less

This User Gave Thanks to frank_rizzo For This Post:
# 3  
Old 01-07-2012
Ah, excellent! So simple when you think about it.

Thanks Frank :-)
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Script to search log file for last 15 mins data

Hi All, I have an issue which I'm trying to understand a way of doing, I have several nodes which contain syslog events which I want to force trigger an email initially (eventually leading to another method of alerting but to start with an email). Basically the syslog file will have hours worth... (6 Replies)
Discussion started by: mutley2202
6 Replies

2. Shell Programming and Scripting

String search in log file

hi, i have a requirement to search for a sting "/user/data/<7digit>/<temp dir>/<file name>#<unique string> in a log file. This string present number of times but i need to get the first occurence only. i am trying with the below option but not working can you please help. grep... (1 Reply)
Discussion started by: Satyak
1 Replies

3. UNIX for Dummies Questions & Answers

Search file or log for words or strings

i want to search a log for occurrences of words and i want the result to tell me how many lines in the log contained each word. if i type a command like this: egrep "cat|dog|monkey|bananas|bike" logfile i would like a response like this: cat=3,dog=17,monkey=1,bananas=102,bike=51 the... (12 Replies)
Discussion started by: SkySmart
12 Replies

4. Shell Programming and Scripting

How to search log file from a date

Hi All, I want to grep through all the log files created from 20th August. How do I do that? My script will run everyday. So it will take current date as To_Date. My log file name looks like - applog-2012-08-20-000001....applog-2012-08-20-000002...etc. Thanks in advance. (5 Replies)
Discussion started by: kmajumder
5 Replies

5. Shell Programming and Scripting

need help in search the error messages from log file

Hi, My log file has error messages, universal no and universal ID. The problem is i have to search Universal ID from the error messages. But the log file write error messages with universal no and error messages in one line. and universal no with universal ID in other line. So i write two loops... (5 Replies)
Discussion started by: pjlotiya
5 Replies

6. Shell Programming and Scripting

Search a pattern in a log file

I have file which gets updated every minute/second. Is it possible in shell scripting that I can search for some pattern infinitely in this file and if it finds that pattern, alert the user. A sample of log file is below. The following file is getting updated every second. I want to alert the... (2 Replies)
Discussion started by: Tuxidow
2 Replies

7. Shell Programming and Scripting

search latest version of log file

Have checked the forums and couldnt locate help on this. I want to grep a log file for a pattern using a script - I need to grep the latest log file and not sure how I am able to ensure I am greping the latest log file. Here is sample of log files for yestersday and I effectively need to grep... (10 Replies)
Discussion started by: frustrated1
10 Replies

8. Shell Programming and Scripting

{How} Script to search a log file for a given criteria

I have to write a script to search the logfiles i.e msg.log for the following The Search Criteria is as follows 1. IP address 2. String Ex: abc.123.com 3. Timestamp ( start - end ) ex: 2008-05-04-00:30:00 - 2008-05-08-04:30:00 Can anyone help to devise a script for... (9 Replies)
Discussion started by: indiakingz
9 Replies

9. Shell Programming and Scripting

String search in log file

Hi all! I have a log file from an incremental backup. This next script I've done works when the backup completes in the same day it started. But if the backup goes on to the next day, this one doesn't work anymore. ################################## #VARS data=`date '+%m/%d/%y'`... (1 Reply)
Discussion started by: sliver
1 Replies

10. Shell Programming and Scripting

search log file

hi, I know this question probably been asked a thousand times but I can't find any posts that can help me out, so here I am. The problem is at the end of the day I want to execute a script but I only want to invoke it if and only if scripts 1/2/3/4/5/6 executed successfully. So what I did is to... (1 Reply)
Discussion started by: mpang_
1 Replies
Login or Register to Ask a Question