From: www on
Hi,

My file looks like:

<parameter id="ABC_FLOW_TIME_1_HOUR">
<dblValue>24</dblValue>
</parameter>
<parameter id="ABC_FLOW_TIME_3_HOUR">
<dblValue>0</dblValue>
</parameter>

I want to find any line containing "ABC_FLOW_TIME" and then replace
"dblValue" of the next line to "intValue".

How can I do it with sed? I use sed for the basic substitution, not like
this complicated case. Thank you very much.

From: J G Miller on
On Wed, 10 Mar 2010 12:10:21 -0500, www wrote:

> I want to find any line containing "ABC_FLOW_TIME" and then replace
> "dblValue" of the next line to "intValue".

You need a pattern to match the "first" line, and then the n
command to go on to the next and s to do the substitution.

A simple example to find the line with SECOND and then change the next
line from "data line" to "line of data" --


cat test.dat ; \
echo; \
sed -e '/SECOND/{n; s|data line|line of data|}' test.dat

TITLE

This is FIRST data line
This is SECOND data line
This is THIRD data line
This is FOURTH data line

FOOTER

TITLE

This is FIRST data line
This is SECOND data line
This is THIRD line of data
This is FOURTH data line

FOOTER
From: www on
J G Miller wrote:
> On Wed, 10 Mar 2010 12:10:21 -0500, www wrote:
>
>> I want to find any line containing "ABC_FLOW_TIME" and then replace
>> "dblValue" of the next line to "intValue".
>
> You need a pattern to match the "first" line, and then the n
> command to go on to the next and s to do the substitution.
>
> A simple example to find the line with SECOND and then change the next
> line from "data line" to "line of data" --
>
>
> cat test.dat ; \
> echo; \
> sed -e '/SECOND/{n; s|data line|line of data|}' test.dat
>
> TITLE
>
> This is FIRST data line
> This is SECOND data line
> This is THIRD data line
> This is FOURTH data line
>
> FOOTER
>
> TITLE
>
> This is FIRST data line
> This is SECOND data line
> This is THIRD line of data
> This is FOURTH data line
>
> FOOTER

Thank you very much. I have used the following commands and have
successfully modified myfile.xml:

my file "program.sed" has the content in it:

/ABC_FLOW_TIME/{n; s/dblValue/intValue/g}

sed -f program.sed -i myfile.xml

It works great.
From: Torsten Mueller on
J G Miller <miller(a)yoyo.ORG> schrieb:

> You need a pattern to match the "first" line, and then the n command
> to go on to the next and s to do the substitution.

Thanks! (You never end learning sed ...)

T.M.
From: J G Miller on
On Thu, 11 Mar 2010 06:58:53 +0100, Torsten Mueller wrote:

> Thanks! (You never end learning sed ...)

Yes, doing things on the next or N+1 lines is always one of the
more tricky aspects of sed, along with the concepts of "hold space"
and "pattern space" (which I always have to look up because
I rarely need to use the "hold space" feature).

What annoys me most though, is people who resort to awk
to change things on one line. awk is for manipulating columns
of data, not just changing or selecting a single field or two on
one line ;)
 |  Next  |  Last
Pages: 1 2 3
Prev: Passover Seder plates !!!
Next: Firefox P.O.S.