Need to find a multiple line block and replace with a multiple line block

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need to find a multiple line block and replace with a multiple line block
# 1  
Old 08-22-2009
Need to find a multiple line block and replace with a multiple line block

I would perfer to use cut and paste to do this but I can't find a GUI to do this with. What I want to do is to find a multiple line block of code like

Exit Sub


then replace it with

GoTo RSLogRtn
Exit Sub


Basically it is just an insert, but I may want to replace whole line blocks of code at some time. How can this be accomplished. I tried using V-Grep but to no avail. It will only replace the line block with a string and you can't use expressions in the replace test.
# 2  
Old 08-22-2009
can you elaborate more by giving your exact inputfile and desired output.
# 3  
Old 08-22-2009
It's all there in the post...

Input: Text
OutPut: Text
Desire: Change from first text to second text...
# 4  
Old 08-22-2009
Try this then...

>cat file
Exit Sub
>awk '/Exit/{err=$0;getline;getline;if($0 ~ /Log_Handler:/){print "GoTo RSLogRtn" RS err RS RS $0}}' file
GoTo RSLogRtn
Exit Sub

# 5  
Old 08-22-2009
I will try it. Does this find/replace every reference in the file?
# 6  
Old 08-22-2009
yes, if it is the same as your example. And if that's how you wanted it, redirect to another file.
# 7  
Old 08-22-2009
Yes, to redirect the whole contents with the changes to another file.

---------- Post updated at 11:42 PM ---------- Previous update was at 11:37 PM ----------

Ok, now I have to find a version of AWK or GAWK that works in Windows.

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Using awk to multiple and replace in a specific line

Hi Folks, I have the file in which I need to multiply the content of a line and replace the initial content of that line with the obtained answer. For example if this is my input file file1.txt 2.259314750 xxxxxx 1.962774350 xxxxxx 2.916817290 xxxxxx 1.355026900 ... (4 Replies)
Discussion started by: Madiouma Ndiaye
4 Replies

2. Shell Programming and Scripting

Combining multiple block of lines in one comma separated line

Hi Everyone, On my Linux box I have a text file having block of few lines and this block lines separated by one blank line. I would like to format and print these lines in such a way that this entire block of lines will come as single comma separated line & again next block of lines in next... (7 Replies)
Discussion started by: gr8_usk
7 Replies

3. Shell Programming and Scripting

Multiple line search, replace second line, using awk or sed

All, I appreciate any help you can offer here as this is well beyond my grasp of awk/sed... I have an input file similar to: &LOG &LOG Part: "@DB/TC10000021855/--F" &LOG &LOG &LOG Part: "@DB/TC10000021852/--F" &LOG Cloning_Action: RETAIN &LOG Part: "@DB/TCCP000010713/--A" &LOG &LOG... (5 Replies)
Discussion started by: KarmaPoliceT2
5 Replies

4. Shell Programming and Scripting

Multiple Line awk search and replace

I have a log file that contains many lines but contains the following line three times: related_pin : "t_bypass"; Here are the 3 occurrences and the two lines after from my file.txt: related_pin : "t_bypass"; sdf_cond : "rstq_b"; timing_sense : negative_unate; ... (6 Replies)
Discussion started by: bobbygb2003
6 Replies

5. Shell Programming and Scripting

perl: replace multiple word on a line

Hi All, If I have a line as following: ( MA "vertical" ) How can I convert it to as below: ( BC "horizontal" ) Thanks, --Michael (6 Replies)
Discussion started by: mxn731
6 Replies

6. Shell Programming and Scripting

SED : Replace whole line on multiple execution

Hi, I am have one file with a line group=project_live I need to replace it with line group=project_live_support before I execute some application related script. The potentianl problem is when I replace this with sed using command sed... (2 Replies)
Discussion started by: bhaskar_m
2 Replies

7. Shell Programming and Scripting

Single/Multiple Line with Special characters - Find & Replace in Unix Script

Hi, I am creating a script to do a find and replace single/multiple lines in a file with any number of lines. I have written a logic in a script that reads a reference file say "findrep" and populates two variables $FIND and $REPLACE print $FIND gives Hi How r $u Rahul() Note:... (0 Replies)
Discussion started by: r_sarnayak
0 Replies

8. Shell Programming and Scripting

Replace text block in multiple files

I need to replace (delete) a text block in a bunch of files, its a html table, almost at the end of pages but the location varies. In Windows I used Filemonkey, but nothing like that in Unix? There is replace from mysql, but how does it deal with newlines? sed only works with single lines,... (6 Replies)
Discussion started by: eiland
6 Replies

9. Shell Programming and Scripting

Find 5 lines and replace with 18 line in sql file where it contains multiple blocks.

My sql file xyz_abc.sql in this file there are multiple sql block in this block I need to find the following block rem Subset Rows (&&tempName.*) CREATE VIEW &&tempName.* AS SELECT * FROM &&tempName.* WHERE f is not null and replace with following code rem Subset Rows... (9 Replies)
Discussion started by: Zaheer.mic
9 Replies

10. Shell Programming and Scripting

sed replace multiple occurrences on the same line, but not all

Hi there! I am really enjoying working with sed. I am trying to come up with a sed command to replace some occurrences (not all) in the same line, for instance: I have a command which the output will be: 200.300.400.5 0A 0B 0C 01 02 03 being that the last 6 strings are actually one... (7 Replies)
Discussion started by: ppucci
7 Replies
Login or Register to Ask a Question