How to convert grep to sed??


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to convert grep to sed??
# 1  
Old 05-16-2005
How to convert grep to sed??

Hi,

I am hing problem in grep..
So I need convert following code to sed based one..

grep -ie "error|exception" $LOG_DIR/Node$i\Log.txt >> $LOG_ERR_REP

thats is I want to serach error and exception (ignore case) and write to other file .

how to do?
# 2  
Old 05-16-2005
You can try as,

sed -e "/[eE][rR][rR][oO][rR]/p;/[eE][xX][cC][eE][pP][tT][iI][oO][nN]/p" $LOG_DIR/Node$i\Log.txt >> $LOG_ERR_REP

It will work.
# 3  
Old 05-16-2005
Hi,
Thanks for your help..
But its giving file not containing Error (error) and Exception(and exception) line too???
# 4  
Old 05-16-2005
There is an error in my reply. use this,
sed -n '/[eE][rR][rR][oO][rR]/p;/[eE][xX][cC][eE][pP][tT][iI][oO][nN]/p' $LOG_DIR/Node$i\Log.txt >> $LOG_ERR_REP
# 5  
Old 05-16-2005
thanks ..its working
# 6  
Old 05-16-2005
Quote:
Originally Posted by redlotus72
Hi,

I am hing problem in grep..
So I need convert following code to sed based one..

grep -ie "error|exception" $LOG_DIR/Node$i\Log.txt >> $LOG_ERR_REP

thats is I want to serach error and exception (ignore case) and write to other file .

how to do?
Firstly, what is wrong with your grep? I suspect you are using GNU grep and want extended regexes - in which case you need upper case -E

grep -i -E "error|exception" file >> another_file

Or, if you're not using GNU grep

egrep -i "error|exception" file >> another_file

Also; why are you backslash escaping the L of Log.txt?

Cheers
ZB
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to use sed to look for the particular pattren and convert?

Hi , How do i use sed on a tsv file and look for the date format mm/dd/yyyy and convert it to yyyy-mm-dd. There are around 15 colums in that file and two colums need to be converted. i tried using this but didnt work.Can some one tweek it. sed -e "s_\(..\)\-\(..\)\-\(..\)_\3-\1-\2_" My... (8 Replies)
Discussion started by: vikatakavi
8 Replies

2. Shell Programming and Scripting

sed convert date/replace

Hi, I wold like to replace this 2012 Mar 02 to this 20120302. i have already this code: ls -lrt | awk '{ print $8$6$7 }'| sed -e s/*:*/'2013'/g -e s/'Jan'/01/g -e s/'Feb'/02/g -e s/'Mar'/03/g -e s/'Apr'/04/g -e s/'May'/05/g -e s/'Jun'/06/g -e s/'Jul'/07/g -e s/'Aug'/08/g -e... (7 Replies)
Discussion started by: snayper
7 Replies

3. Shell Programming and Scripting

Grep and convert into columns

I have 1000 different autosys jobs, want to extract only this information using unix commands. Tried with normail greping but unable to make columns into rows. Input: /* ----------------- template ----------------- */ insert_job: template job_type: c box_name: box1 command:... (3 Replies)
Discussion started by: onesuri
3 Replies

4. Shell Programming and Scripting

Convert string using sed

I have a couple structure definitions in my input code. For example: struct node { int val; struct node *next; }; or typedef struct { int numer; int denom; } Rational; I used the following line to convert them into one line and copy it twice. sed '/struct*{/{:l... (3 Replies)
Discussion started by: James Denton
3 Replies

5. Shell Programming and Scripting

awk or sed - Convert 2 lines to 1 line

Hi, Just trying to get to grips with sed and awk for some reporting for work and I need some assistance: I have a file that lists policy names on the first line and then on the second line whether the policy is active or not. Policy Name: Policy1 Active: yes Policy... (8 Replies)
Discussion started by: guinch
8 Replies

6. Programming

SED - how do I convert a decimal number to asterisk

Hi, My animal ID's have two zeros in them and are also converting to asterisk. I only need to change the zero values in columns two and three. I would appreciate any help. This is my data structure: head phendata.txt 201008809 0.0 0.0 201008810 0.0 0.0 201008813 0.0 0.0 201014103... (6 Replies)
Discussion started by: lel7lel7
6 Replies

7. UNIX for Dummies Questions & Answers

grep, sed, awk or tr or all Need help on Trying to convert something.

THIS is the output i Get i want to take out most of the banner and such and leave ------ down to ------ with fields right it doesnt seem to ouput right im not sure how to delete the $ characters because shell sees them ..... thansk or even something that make it looks better to understand... (2 Replies)
Discussion started by: ritztech
2 Replies

8. Shell Programming and Scripting

Convert sed to perl

Can anyone convert this from sed to perl: sed -n '/\var\/log/p' /etc/syslog.conf I think Ive looked at this to much....urgh.. Thanks Ben (5 Replies)
Discussion started by: bigben1220
5 Replies

9. Shell Programming and Scripting

Convert contents of file to lower case with SED

Hi I what to add option to existing sed code to convert target file to lower case #!/bin/ksh SOURCE_DATA_DEST=/ora TARGET_DATA_DEST=/home/oracle/alexz TARGET_DB_SID=T102_test sed -e "s/REUSE/SET/g" \ -e "s/NORESETLOGS/RESETLOGS/g" \ T102_ccf.sql > target.sql Thanks (2 Replies)
Discussion started by: zam
2 Replies

10. Shell Programming and Scripting

SED to convert ~ in a file to newline

Hi, I have a .txt file which has a tilde(~) in it. All that I want is to break into a newline whenever there is an occurence of '~'. I have tried SED to do that but I could not succeed. I would appreciate if I can get a shell script(ksh) for this problem real quick. Thanks in advance. ... (5 Replies)
Discussion started by: ntekupal
5 Replies
Login or Register to Ask a Question