Replace multiple lines between tags using sed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replace multiple lines between tags using sed
# 8  
Old 05-11-2009
Try this:

Code:
awk '/<AFFILIATECODEBEGIN>/{p=1}/<\/AFFILIATECODEBEGIN>/{p=0;next}!p' festivals.html

# 9  
Old 05-11-2009
Try this :

Code:
 
TESTBOX>awk '/<AFFILIATECODEBEGIN>/ { print ; print "something "; next }
> /<\/AFFILIATECODEBEGIN>/ { print ;} ' html.txt
 
o/p :

<AFFILIATECODEBEGIN>
something
</AFFILIATECODEBEGIN>

# 10  
Old 05-11-2009
Thanks to you both. Franklin your command output the contents of the file but no changes, and the output of panyam was:

Code:
awk: cmd. line:1: /<AFFILIATECODEBEGIN>/ { print ; print "something "; next } > /<\/AFFILIATECODEBEGIN>/ { print ;} 
awk: cmd. line:1:                                                             ^ syntax error

The syntax error being the ">" between "next }" and "/<\/"
# 11  
Old 05-11-2009
Quote:
Originally Posted by jdv
Franklin your command output the contents of the file but no changes
This is what I get:

Code:
$ cat file
abc
abc
abc
<AFFILIATECODEBEGIN>

<p align="center">
<script type="text/javascript"><!--
auctionads_ad_client = "editedforprivacy";
auctionads_ad_campaign = "42efbc14b4c2adfae40ff87882f07569";
auctionads_ad_width = "120";
auctionads_ad_height = "240";
auctionads_ad_kw =  "japan";
auctionads_color_border =  "CC0000";
auctionads_color_bg =  "FFFFFF";
auctionads_color_heading =  "000000";
auctionads_color_text =  "000000";
auctionads_color_link =  "FFFFFF";
--></script>

<script type="text/javascript" src="http://ads.auctionads.com/pagead/show_ads.js
">
</script>

</p>

</AFFILIATECODEBEGIN>
xyz
xyz
xyz
$
$
$ awk '/<AFFILIATECODEBEGIN>/{p=1}/<\/AFFILIATECODEBEGIN>/{p=0;next}!p' file
abc
abc
abc
xyz
xyz
xyz
$

# 12  
Old 05-11-2009
Hi jdv,

FYI :

avalon:/disk1/jvsh/TEST>awk '/<AFFILIATECODEBEGIN>/ { print ; print "something "; next }
> /<\/AFFILIATECODEBEGIN>/ { print ;} ' html.txt

> is the character u will get on screen wen u press ENTER , it means the command is continuing in in the next line. it is not the part of the command.


If you put in a single line
Code:
 
 
awk '/<AFFILIATECODEBEGIN>/ { print ; print "something "; next } /<\/AFFILIATECODEBEGIN>/ { print ;} ' input_file.txt

# 13  
Old 05-11-2009
Code:
]# awk '/<AFFILIATECODEBEGIN>/ { print ; print "something "; next }
> /<\/AFFILIATECODEBEGIN>/ { print ;} ' festivals.html
<AFFILIATECODEBEGIN>
something 
</AFFILIATECODEBEGIN>

then nano festivals.html shows nothing has changed in the actual file.

:/

Thanks
# 14  
Old 05-11-2009
Ofcourse nothing will change in the actual file .

You need to redirect the output of the command to some other file to store the data.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace a string with multiple lines

Hello Guys, I need to replace a string with multiple lines. For eg:- ABC,DEF,GHI,JKL,MNO,PQR,STU need to convert the above as below:- ABC,DEF, GHI1 GHI2 GHI3, JKL,MNO, PQR1 PQR2 PQR3, STU i have tried using code as:- (2 Replies)
Discussion started by: jassi10781
2 Replies

2. Shell Programming and Scripting

Sed/awk/perl command to replace pattern in multiple lines

Hi I know sed and awk has options to give range of line numbers, but I need to replace pattern in specific lines Something like sed -e '1s,14s,26s/pattern/new pattern/' file name Can somebody help me in this.... I am fine with see/awk/perl Thank you in advance (9 Replies)
Discussion started by: dani777
9 Replies

3. Shell Programming and Scripting

Replace multiple lines through sed

Hi All, I have a input file as sample below <this is not starting of file> record line1 line2 line3 end line4 line5 record line6 line7 line8 my requirement is this, i want to select a pattern between first record and end, whatever is written between first record and end. and... (0 Replies)
Discussion started by: adgangwar
0 Replies

4. Shell Programming and Scripting

Script to find & replace a multiple lines string across multiple php files and subdirectories

Hey guys. I know pratically 0 about Linux, so could anyone please give me instructions on how to accomplish this ? The distro is RedHat 4.1.2 and i need to find and replace a multiple lines string in several php files across subdirectories. So lets say im at root/dir1/dir2/ , when i execute... (12 Replies)
Discussion started by: spfc_dmt
12 Replies

5. Shell Programming and Scripting

search and replace, when found, delete multiple lines, add new set of lines?

hey guys, I tried searching but most 'search and replace' questions are related to one liners. Say I have a file to be replaced that has the following: $ cat testing.txt TESTING AAA BBB CCC DDD EEE FFF GGG HHH ENDTESTING This is the input file: (3 Replies)
Discussion started by: DeuceLee
3 Replies

6. Shell Programming and Scripting

replace (sed?) a string in file with multiple lines (string) from variable

Can someone tell me how I can do this? e.g: a=$(echo -e wert trewt ertert ertert ertert erttert erterte rterter tertertert ert) How do i replace the STRING with $a? I try this: sed -i 's/STRING/'"$a"'/g' filename.ext but this don' t work (2 Replies)
Discussion started by: jforce
2 Replies

7. Shell Programming and Scripting

replace (sed?) a single line/string in file with multiple lines (string) from another file??

Can someone tell me how I can do this? e.g: Say file1.txt contains: today is monday the 22 of NOVEMBER 2010 and file2.txt contains: the 11th month of How do i replace the word NOVEMBER with (5 Replies)
Discussion started by: tuathan
5 Replies

8. Shell Programming and Scripting

sed find and replace multiple lines

I am new to linux and would like to modify the contents of a file preferably using a one line. The situation is as follows <start> some lines "I am the string" "replace string" more lines here <end> In the above example,On encountering "I am the string", the "replace string "should be... (6 Replies)
Discussion started by: supersimha
6 Replies

9. Shell Programming and Scripting

replace multiple lines in multiple files

i have to search a string and replace with multiple lines. example Input echo 'sample text' echo 'college days' output echo 'sample text' echo 'information on students' echo 'emp number' echo 'holidays' i have to search a word college and replace the multiple lines i have... (1 Reply)
Discussion started by: unihp1
1 Replies

10. Shell Programming and Scripting

using sed command to replace multiple lines

the file contains the follwoing lines /* * Copyright (C) 1995-1996 by XXX Corporation. This program * contains proprietary and confidential information. All rights reserved * except as may be permitted by prior written consent. * * $Id: xxx_err.h,v 1.10 2001/07/26 18:48:34 zzzz $ ... (1 Reply)
Discussion started by: radha.kalivar
1 Replies
Login or Register to Ask a Question