Grepping Errors in a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Grepping Errors in a file
# 1  
Old 02-04-2007
Grepping Errors in a file

Hey All,

I have to grep for an error from a file and get the results of errror in a different file......

But there should be no duplicate entries. Can anyone help me in giving a shell script for this

This is file which contains pattern error which I am supposed to grep and put this in a different file....And this should happen everyday

2007-02-01 23:00:18 Error : this file has error
2007-02-05 24:00:00 date : this afiel ca
2007-02-01 13:00:00 Error : Hi again
2007-02-04 23:00:00 Error : this is again a error
2007-02-04 15:05:00 Error : hi
# 2  
Old 02-04-2007
grep ":[0-9][0-9] : Error :" <file1> | cut -c21- | sort -u > <file2>
# 3  
Old 02-05-2007
Code:
sed -n '/Error/p' currfile | sed 's/\(.*\):\(.*\):\(.*\)/Error :\3/' | sort -u > newfile

# 4  
Old 02-05-2007
Quote:
Originally Posted by matrixmadhan
Code:
sed -n '/Error/p' currfile | sed 's/\(.*\):\(.*\):\(.*\)/Error :\3/' | sort -u > newfile

Code:
sed -n '/Error/s/\(.*\):\(.*\):\(.*\)/Error :\3/p' file

# 5  
Old 02-05-2007
Oh!

Thats a cool one!

The OP had asked for sorted output and thats why sort -u was included.

Hope that was a typo!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

ksh Script, Reading A File, Grepping A File Contents In Another File

So I'm stumped. First... APOLOGIES... my work is offline in an office that has zero internet connectivity, as required by our client. If need be, I could print out my script attempts and retype them here. But on the off chance... here goes. I have a text file (file_source) of terms, each line... (3 Replies)
Discussion started by: Brusimm
3 Replies

2. UNIX for Dummies Questions & Answers

Grepping al values of a particular column in a file

Name Num_free Num_active Pct_act Max_Used Reuse_cnt Instance_Name --------------------------------- --------------- ----------- ------- ----------- ----------- ------------------------------ additional network memory 0 ... (2 Replies)
Discussion started by: Rajeshneemkar
2 Replies

3. Shell Programming and Scripting

Grepping a word from a .xml file

Hi I have a xml file vi lpower.xml <head = power_health> Now, I need to grep "power_health" alone from that file using shell.. Please help (3 Replies)
Discussion started by: Priya Amaresh
3 Replies

4. Shell Programming and Scripting

Display file date after grepping a string in the file

Hi All, I need to recursively grep several folders for a MAC address and display the results with the date of the file name at the start. Even better would be if the final results were displayed chronologically so the newest file is always at the end. Oldest at the top, regardless of what... (8 Replies)
Discussion started by: quemalr
8 Replies

5. Shell Programming and Scripting

Grepping file and returning passed variable if the value does not exist in file at all.

I have a list of fields that I want to check a file for, returning that field if it not found at all in the file. Is there a way to do a grep -lc and return the passed variable too rather then just the count? I am doing some crappy work-around now but I was not sure how to regrep this for :0 so... (3 Replies)
Discussion started by: personalt
3 Replies

6. Shell Programming and Scripting

Grepping string from out file

Guys .. Need to pull this highlighted strings irrespective of line numbers & should be echoed . But these strings are from Outfile from different dir. In which way this can be grepped ?? Need an idea http-timeout 120 seconds persistent-timeout 180 seconds host-rewriting on ... (7 Replies)
Discussion started by: raghunsi
7 Replies

7. Shell Programming and Scripting

Grepping log file

Dear All, I have a log file that is dislpayed as: <msg time='2009-10-14T05:46:42.580+00:00' org_id='oracle' comp_id='tnslsnr' type='UNKNOWN' level='16' host_id='mtdb_a' host_addr='UNKNOWN' version='1'> <txt>14-OCT-2009 05:46:42 *... (19 Replies)
Discussion started by: x-plicit78
19 Replies

8. Shell Programming and Scripting

Loop and grepping into a file

I wrote this script for: 1. Get the Web log for today 2. Give me a list of all the IP addresses that have accessed the web server today 3. Remove a list of known IPs listed in a file (line by line) 4. Mail the final file to selected recipients. I am unable to do part 3. In the script... (3 Replies)
Discussion started by: skotapal
3 Replies

9. UNIX for Dummies Questions & Answers

grepping the first 3 characters from a file

give this a try and let me know if it works grep '^' filename rachael (2 Replies)
Discussion started by: rachael
2 Replies

10. UNIX for Dummies Questions & Answers

grepping the first 3 characters from a file

Hi I was wondering if it's possible to use a command to get the first 3 characters of a line in a text file, I tried grep but it returns the whole line but I am only interested in the first 3 characters. Is this possible with grep or I need any other command? Also is it possible deleting from... (2 Replies)
Discussion started by: g-e-n-o
2 Replies
Login or Register to Ask a Question