sed and egrep question

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed and egrep question
# 1  
Old 03-24-2014
sed and egrep question

Its really 2 questions, but both are pretty basic.
Linux Redhat

1. Need to do a search and replace on a file.
I need to append '--' (comment out the line) to specific lines based on a wildcard search.

So if I Have


I dont care what comes after that. SOME_ROLE_OR_USER will change so Ill edit it as needed. I can't guarantee the number of spaces after GRANT. I also need this to be case insensitive.

2. Egrep:

SOME ORACLE COMMAND <should be one line
ERROR at line 1:
ORA-0000: some error message

-- Notes
Could be ORA-, PLS-,TNS-, or possible 1 or 2 other things.
May be multiple lines of ORA/PLS and could be a mixture.

I need to return, The command above (I believe its always indented) and then the oracle error message and number which can be more than 1 line.

I do not think the multiple lines of Oracle Error messages will have 'spaces' between them'
I can't guarantee you will see ERROR at Line 1: (or whatever number), but
ORA-,PLS-,TNS-, (And possible some others I can find will be present)

I need to find this. So I can just pull out error messages and the command that caused the error from a log file.

Moderator's Comments:
Mod Comment If you have two distinct questions then please open two threads.. And use a more descriptive title than sed question or egrep question

Last edited by Scrutinizer; 03-24-2014 at 06:43 PM..
# 2  
Old 03-24-2014
1) Do you want to append "--" or do you want to prefix the line with it?
2) Did you try egrep -B2 -A1 "^ERROR", given your egrep allows for it?
# 3  
Old 03-25-2014
Had a look at your question 1, will the following be sufficient for your requirement?

[soliton@UAT:test]$ cat test.txt
[soliton@UAT:test]$ sed -e 's/^\(GRANT.*\)/--\1/i' test.txt
--grant ABC XXXXXX;

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Lines of code in egrep question

Hi, I have a question, during my readings it appears that these two variables in the snippet below need to be on the same line to return a “true” answer and listed in the output otherwise it won’t be returned. How can I write this snippet to make it return a “true” if those two variables are on... (6 Replies)
Discussion started by: bdby
6 Replies

2. Shell Programming and Scripting

sed and egrep in perl

Hi i have a data file whcih contains the data as follows : FH332OY86|AAABBB CCCC DDDA FHLMC 30 8.000|FHLMC|3|30|8.00000000|1986|26.29164289|3.29544844|0.00000000|10.05940539|107.50704264|Mar 8 2013 12:00AM|20130311|D|DA|DAA|DAAC|201302 FH332OY87|AAABBB CCCC DDDA FHLMC 30... (9 Replies)
Discussion started by: ptappeta
9 Replies

3. Shell Programming and Scripting

Patterns with egrep/sed/awk?

I have an array with characters, what I want is if there are other characters in the array which I am looking for than take action that is print BAD ARRAY. So far my code just finds characters but instead I want that it should look for other characters. echo "A B C D F" | egrep -o "D | F" O/P... (5 Replies)
Discussion started by: dixits
5 Replies

4. Shell Programming and Scripting

regex question using egrep

Hi, i have a a bunch of directories that are always named with six lowercase alpha's and either one or two numeric's (but no more) so for example names could be qwerty1 qwerty9 qwerty10 qwerty67 I am currently using two pattern matches to capture these names echo $DIR |... (8 Replies)
Discussion started by: rethink
8 Replies

5. UNIX for Dummies Questions & Answers

egrep count question

Hello all, I'm a first time poster and a unix/linux noob so please be understanding. I am trying this command below: # egrep -c "Oct".+"Connect: ppp" /var/log/messages* /var/log/messages:53 /var/log/messages.1:35 /var/log/messages.2:63 /var/log/messages.3:27 /var/log/messages.4:12 ... (1 Reply)
Discussion started by: morrowtech
1 Replies

6. Shell Programming and Scripting

egrep question

I want to egrep for certain fields which are not existing in the current log files and am getting errors for that... egrep "'^20090220.14'|'^20090220.15'|'^20090220.16'|'^20090220.17'|'^20090220.18'" Some of the times are in future and logs don't have those entries and I get errors for them... (1 Reply)
Discussion started by: jacki
1 Replies

7. UNIX for Dummies Questions & Answers

Egrep question

I have a script that does the following. It searches a listing of directories with specific extensions and then formats a wc on those files. The code looks like this find <directory> -name '*.js' -o -name '*.html' | awk '{print \"wc -l \"$1}' > file \n" The result is a file with the "wc -l"... (7 Replies)
Discussion started by: mastachef
7 Replies

8. UNIX for Dummies Questions & Answers

Egrep cheat sheet anywhere? Looking for meaning of egrep -c

Hi I've been searching google and have not found what egrep -c means. Does anyone know where I can get a cheat sheet or what that -c means? thanks, Linda (2 Replies)
Discussion started by: leelm
2 Replies

9. UNIX for Dummies Questions & Answers

question on egrep

Hi I am trying to use this command: egrep '^a{2,6}$' testexpr4D to retreive lines with 2,3,4,5, or 6 a's in a file . The file testexpr4D has entries like: a aa aaa aaaa aaaaa aaaaaa 123456 ABCDEF I was expecting to see 5 lines in the output but nothing happens. Can anyone help... (10 Replies)
Discussion started by: rohitv
10 Replies

10. Shell Programming and Scripting

egrep vs. sed backreference

My egrep outputs this: $ cat html.out|sed -n '/bluetext/s/&nbsp;/ /gp'|egrep '{5}' <span class="bluetext"><b> Lexington Park, MD 20653</b></span> But my backreference \1 is empty. I dont understand why. Can someone clarify? $ cat html.out|sed -n '/bluetext/s/&nbsp;/ /gp'|sed -n... (1 Reply)
Discussion started by: r0sc0
1 Replies
Login or Register to Ask a Question