Insert Text after searching via grep


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Insert Text after searching via grep
# 1  
Old 03-18-2014
Insert Text after searching via grep

Hi Team,

I have a file with the following patterns:
Code:
 ==> xyz_Server_Started_with_Errors  <==
errors.

    ==> abc_Server_Started_with_Errors  <==
errors

  
==> reds_Server_Started_with_Errors  <==
errorss

I want them in this format:

Code:
===================================================
 ==> xyz_Server_Started_with_Errors  <==
===================================================

errors


===================================================

    ==> abc_Server_Started_with_Errors  <==
==================================================

errors


==================================================

  
==> reds_Server_Started_with_Errors  <==
==================================================

errorss

Thanks for the help Smilie






# 2  
Old 03-18-2014
What have you tried?
# 3  
Old 03-18-2014
Code:
sed -i '/*Started_with_Errors/a =========================' one.txt > two.txt

But this doesnt seem to work
# 4  
Old 03-18-2014
Code:
sed '/Started_with_Errors/{s/^/===================================================\
/;s/$/\
===================================================/;}' one.txt > two.txt

This User Gave Thanks to anbu23 For This Post:
# 5  
Old 03-18-2014
Can you please quickly explain?
# 6  
Old 03-18-2014
If a line contains pattern /Started_with_Errors/, then perform two substitution.

1. Add "=======...\n" at the beginning of line containing pattern /Started_with_Errors/
Code:
s/^/===================================================\
/

2. Add "\n=======..." at the end of the line containing pattern /Started_with_Errors/
Code:
s/$/\
===================================================/

---------- Post updated at 04:10 AM ---------- Previous update was at 03:37 AM ----------

Code:
sed '/Started_with_Errors/{ i\
===================================================
a\
===================================================
}' one.txt > two.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Searching for exact match using grep

I am searching for an exact match on a value read from another file to lookup an email address in another file. The file being checked is called "contacts" and it has Act #, email address, and contact person. 1693;abc1693@yahoo.comt;Tommy D 6423;abc6423@yahoo.comt;Jim Doran... (2 Replies)
Discussion started by: ziggy6
2 Replies

2. Shell Programming and Scripting

searching a file with a specified text without using conventional file searching commands

without using conventional file searching commands like find etc, is it possible to locate a file if i just know that the file that i'm searching for contains a particular text like "Hello world" or something? (5 Replies)
Discussion started by: arindamlive
5 Replies

3. Shell Programming and Scripting

grep searching interval

Hi all, I just want to find all values that are in a specified interval. I tryed it with grep e- file , it does not work. Is it possible to get values wich are lower a special number, like grep >e-18 file? Thanks a lot (4 Replies)
Discussion started by: newcommer
4 Replies

4. Shell Programming and Scripting

Insert tags in lines after searching for a word

Hi, I am new to Unix and this is my first post on this forum. I am trying to convert a file into an xml. In my input I want to search for any line that starts with a 'F' and make it a tag in the xml. See below for the input and output. Input : <Payment> <REFERENCE>78</REFERENCE> F123 : ... (7 Replies)
Discussion started by: akashgov
7 Replies

5. Shell Programming and Scripting

grep searching

I am making a script but having little problem. at one part I need to find one number format or other format from a file.. those formats are xxx-xx-xxxx or xxxxxxxxx i tried grep '( \{3\}-\{2\}-\{3\} |\{9\})' if i do them sepratly it work but like this it is not working Please check... (7 Replies)
Discussion started by: Learnerabc
7 Replies

6. Shell Programming and Scripting

searching using grep command

Hi, i have a file called alert_pindb.log i need to grep and count for all the lines starting with "ORA-" but i need to exclude the line which is having "ORA-00600 " i am using following syntax to count the ORA- nos "grep \"ORA-\" alert_pindb.log | wc -l"; since ORA- may be anything... (9 Replies)
Discussion started by: prakash.gr
9 Replies

7. Shell Programming and Scripting

Need to insert new text and change existing text in a file using SED

Hi all, I need to insert new text and change existing text in a file. For that I used the below line in the command line and got the expected output. sed '$a\ hi... ' shell > shell1 But I face problem when using the same in script. It is throwing the error as, sed: command garbled:... (4 Replies)
Discussion started by: iamgeethuj
4 Replies

8. Shell Programming and Scripting

How to insert some constant text at beginig of each line within a text file.

Dear Folks :), I am new to UNIX scripting and I do not know how can I insert some text in the first column of a UNIX text file at command promtp. I can do this in vi editor by using this command :g/^/s//BBB_ e,g I have a file named as Test.dat and it containins below text: michal... (4 Replies)
Discussion started by: Muhammad Afzal
4 Replies

9. Shell Programming and Scripting

GREP Searching for a newbie...

Hi, I really need some help with GREP searching... I need to find all occurances of a file reference and remove two characters from the end of the reference. For example, here are a few lines showing the text: <image file="STRAIGHT_004CR.jpg" ALT="STRAIGHT_004CR.jpg" /> <image... (8 Replies)
Discussion started by: steveglevin
8 Replies

10. Shell Programming and Scripting

grep - searching for a specific string

ppl, this is my "file" with fields orderno orderdate orderdesc telno street city 1 01/04/2006 abc 123 100 tampa 2 01/04/2006 abc 123 100 tampa 3 01/04/2006 abc 123 100 tampa 4 01/04/2006 abc ... (2 Replies)
Discussion started by: manthasirisha
2 Replies
Login or Register to Ask a Question