Sponsored Content
Top Forums Shell Programming and Scripting sed search and replace in next line Post 302127972 by charissaf67 on Friday 20th of July 2007 12:41:07 PM
Old 07-20-2007
sed search and replace in next line

Hello,

I am hoping someone can provide some guidance on using context based search and replace to search for a pattern and then do a search and replace in the line that follows it. For example, I have a file that looks like this:

<bold>bold text
</italic>
somecontent
morecontent
<italic>italic text
</italic>
somecontent
morecontent
<bold>bold text
</italic>

Basically, I'd like to look for lines containing the <bold> tag, and then search and replace the </italic> tag with the proper closing </bold> tag. The goal is not to disturb the tags that should remain italic.

<bold>bold text
</bold>

I'm not married to doing this with sed, but it would be great to have a simple one-liner to accomplish this. For ex, I've attempted to do this using something like:
sed '/<bold>/,+1 s/<\/italic>/<\/bold>/g'
But I am not sure that my syntax is correct.

Appreciate the help.
Thanks.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl: Search for string on line then search and replace text

Hi All, I have a file that I need to be able to find a pattern match on a line, search that line for a text pattern, and replace that text. An example of 4 lines in my file is: 1. MatchText_randomNumberOfText moreData ReplaceMe moreData 2. MatchText_randomNumberOfText moreData moreData... (4 Replies)
Discussion started by: Crypto
4 Replies

2. UNIX for Dummies Questions & Answers

How to search and replace a particular line in file with sed command

Hello, I have a file and in that, I want to search for a aprticular word and then replace another word in the same line with something else. Example: In file abc.txt, there is a line <host oa_var="s_hostname">test</host> I want to search with s_hostname text and then replace test with... (2 Replies)
Discussion started by: sshah1001
2 Replies

3. Shell Programming and Scripting

Does Sed Search/Replace Work For Multiple Matches On The Same Line?

Hello, I would like to delete all the footnotes in all my htm files. Hence, I have to delete the whole font tag pairs, i.e. deleting everything between the begin/end font tags. I create a testfile, of which data parts of all four lines are the same except for the number of font tag pairs,... (3 Replies)
Discussion started by: cibalo
3 Replies

4. Shell Programming and Scripting

sed search and replace

hi, im new for sed, anyone can help me to these in sed command my output file.txt "aaa",a1,bbb "ddd",a1,ccc "eee",a1,www need to change a1, to "a1"," output i need "aaa","a1","bbb "ddd","a1","ccc "eee","a1","www thanks in advance fsp (2 Replies)
Discussion started by: fspalero
2 Replies

5. Shell Programming and Scripting

SED Question: Search and Replace start of line to matching pattern

Hi guys, got a problem here with sed on the command line. If i have a string as below: online xx:wer:xcv: sdf:/asdf/http:https-asdfd How can i match the pattern "http:" and replace the start of the string to the pattern with null? I tried the following but it doesn't work: ... (3 Replies)
Discussion started by: DrivesMeCrazy
3 Replies

6. UNIX for Advanced & Expert Users

Search Parameter in first line and replace next line content

Hi, I need help. I have XML file as below &lt;a n=&quot;infoLevel&quot;&gt; &lt;v s=&quot;true&quot;/&gt; &lt;/a&gt; &lt;a n=&quot;localAddr&quot;&gt; &lt;v s=&quot;server.host.com&quot;/&gt; &lt;/a&gt; &lt;a n=&quot;ListenPort&quot;&gt; &lt;v s=&quot;21111&quot;/&gt; &lt;/a&gt; I need to find variable "ListenPort" in line and then replace... (4 Replies)
Discussion started by: rdtrivedi
4 Replies

7. Shell Programming and Scripting

perl search and replace - search in first line and replance in 2nd line

Dear All, i want to search particular string and want to replance next line value. following is the test file. search string is tmp,??? ,10:1 "???" may contain any 3 character it should remain the same and next line replace with ,10:50 tmp,123 --- if match tmp,??? then... (3 Replies)
Discussion started by: arvindng
3 Replies

8. UNIX for Dummies Questions & Answers

How to use 'sed' to search and replace?

Hello - I have a very large file in which a certain numbers are repeated. I find that using vi to edit the entire file is useless. How should i use sed to find a replace such as this text: To replace: 145.D25.D558 With: 215.22.45.DW I tried this command: sed... (4 Replies)
Discussion started by: DallasT
4 Replies

9. Shell Programming and Scripting

sed command to replace a line at a specific line number with some other line

my requirement is, consider a file output cat output blah sdjfhjkd jsdfhjksdh sdfs 23423 sdfsdf sdf"sdfsdf"sdfsdf"""""dsf hellow there this doesnt look good et cetc etc etcetera i want to replace a line of line number 4 ("this doesnt look good") with some other line ... (3 Replies)
Discussion started by: vivek d r
3 Replies

10. 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
MAN(6)								   Games Manual 							    MAN(6)

NAME
man - macros to typeset manual SYNOPSIS
nroff -man file ... troff -man file ... DESCRIPTION
These macros are used to format pages of this manual. Except in and requests, any text argument denoted t in the request summary may be zero to six words. Quotes " ... " may be used to include blanks in a `word'. If t is empty, the special treatment is applied to the next text input line (the next line that doesn't begin with dot). In this way, for example, .I may be used to italicize a line of more than 6 words, or .SM followed by .B to make small letters in `bold' font. A prevailing indent distance is remembered between successive indented paragraphs, and is reset to default value upon reaching a non- indented paragraph. Default units for indents i are ens. The fonts are R roman, the main font, preferred for diagnostics I italic, preferred for parameters, short names of commands, names of manual pages, and naked function names `bold', actually the constant width font, preferred for examples, file names, declarations, keywords, names of struct members, and literals (numbers are rarely literals) L also the constant width font. In troff L=B; in nroff arguments of the macros .L, .LR, and .RL are printed in quotes; preferred only where quotes really help (e.g. lower-case literals and punctuation). Type font and size are reset to default values before each paragraph, and after processing font- or size-setting macros. The -man macros admit equations and tables in the style of eqn(1) and tbl(1), but do not support arguments on .EQ and .TS macros. These strings are predefined by -man: *R `(Reg)', trademark symbol in troff. *S Change to default type size. FILES
/sys/lib/tmac/tmac.an SEE ALSO
troff(1), man(1) REQUESTS
Request Cause If no Explanation Break Argument .B t no t=n.t.l.*Text t is `bold'. .BI t no t=n.t.l. Join words of t alternating bold and italic. .BR t no t=n.t.l. Join words of t alternating bold and Roman. .DT no Restore default tabs. .EE yes End displayed example .EX yes Begin displayed example .HP i yes i=p.i.* Set prevailing indent to i. Begin paragraph with hanging indent. .I t no t=n.t.l. Text t is italic. .IB t no t=n.t.l. Join words of t alternating italic and bold. .IP x i yes x="" Same as .TP with tag x. .IR t no t=n.t.l. Join words of t alternating italic and Roman. .L t no t=n.t.l. Text t is literal. .LP yes Same as .PP. .LR t no Join 2 words of t alternating literal and Roman. .PD d no d=.4v Interparagraph distance is d. .PP yes Begin paragraph. Set prevailing indent to default. .RE yes End of rel- ative indent. Set prevailing indent to amount of starting .RS. .RI t no t=n.t.l. Join words of t alternating Roman and italic. .RL t no Join 2 or 3 words of t alternating Roman and literal. .RS i yes i=p.i. Start relative indent, move left margin in distance i. Set prevailing indent to default for nested indents. .SH t yes t="" Subhead; reset paragraph distance. .SM t no t=n.t.l. Text t is small. .SS t no t="" Secondary subhead. .TF s yes Prevailing indent is wide as string s in font L; para- graph distance is 0. .TH n c x yes Begin page named n of chapter c; x is extra commentary, e.g. `local', for page head. Set prevailing indent and tabs to default. .TP i yes i=p.i. Set prevailing indent to i. Restore default indent if i=0. Begin indented paragraph with hanging tag given by next text line. If tag doesn't fit, place it on separate line. .1C yes Equalize columns and return to 1-column output .2C yes Start 2-column nofill output * n.t.l. = next text line; p.i. = prevailing indent BUGS
There's no way to fool troff into handling literal double quote marks " in font-alternation macros, such as There is no direct way to suppress column widows in 2-column output; the column lengths may be adjusted by inserting requests before the closing MAN(6)
All times are GMT -4. The time now is 12:02 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy