Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to work with block in loop by using sed?

Tags:

loops

sed

block

I have file with some blocks, like this:

<start> test var=3333
<g>test=000000000000 tst <s>
<end>
...
<start> var=564735628
<title>somethink<\title>
<end>
...

And I need to get block between and sections in a loop. And then I need to get some simbols in the current block. I try to do like this:

for block in $(cat $file | sed -n '/<start>/,/<end>/p;'); do
         echo $block 
done

Result is:

<start>

instead

<start> test 1
<g>test=000000000000 tst <s>
<end>

How can I get the entire block for further processing?


Ok, I try to explain Source is

<start> test var=3333
<g>test=000000000000 tst <s>
<end>

Result of yours code is not a block. It is just a sting. The string is <end>t> test var=3333tst <s> As can you see it is overlaping strings of the block on each other.

like image 475
Alex Avatar asked Dec 13 '25 19:12

Alex


1 Answers

One sugession, do not used sed here. Use languages like perl or python which gives modules for parsing HTML and XML.

like image 51
Mandar Pande Avatar answered Dec 16 '25 07:12

Mandar Pande



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!