LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   bash script to apply sed command only to a specific text area (https://www.linuxquestions.org/questions/programming-9/bash-script-to-apply-sed-command-only-to-a-specific-text-area-569106/)

mauran 07-13-2007 01:28 PM

bash script to apply sed command only to a specific text area
 
Dear all,

I need to apply an sed argument to specific text area in a html file.

first need to find the pattern <font=xxx> </font>

then apply sed argument within the font tag only.

can any one help me to write this bash script?

acid_kewpie 07-13-2007 01:36 PM

well that's the point of sed...

sed 's/\<font color\=red/\<font color\=blue/g' file.txt

should do it as an example.

mauran 07-13-2007 02:05 PM

Quote:

Originally Posted by acid_kewpie
well that's the point of sed...

sed 's/\<font color\=red/\<font color\=blue/g' file.txt

should do it as an example.

sorry.

My need is not just changing the font tag. I don't want to change it. I need to apply a sed argument to the text which coming within the specific font tag.

The argument should not be applied to the other text in that html file.

pixellany 07-13-2007 02:38 PM

Quote:

Originally Posted by mauran
sorry.

My need is not just changing the font tag. I don't want to change it. I need to apply a sed argument to the text which coming within the specific font tag.

The argument should not be applied to the other text in that html file.

He just gave an example.....

The sed replace (s) command will change the 1st instance or, with the "g" added, ALL instances. I seem to recall that there is a way to select a specific number of instances.

My favorite tutorial on sed is here: http://www.grymoire.com/Unix/Sed.html

It will help to post an example of text that you want to change.

acid_kewpie 07-13-2007 02:39 PM

that's still just a standard sed command, not sure what the issue is...



sed 's/\<font color\=red\>some\ data\ here/\<font color\=red\>some\ new\ data/g' file.txt

mauran 07-13-2007 02:47 PM

ok I'll explain it in detail.

here is the html file.

Quote:

<BODY LANG="en-US" DIR="LTR">
<P STYLE="margin-bottom: 0cm"><FONT FACE="Bamini">kl;lf;fsg;G
<FONT FACE="Bitstream Charter, serif">(baticoloa)</FONT> rpj;jhz;b
Nfhusq;Nfzp gpuNjrj;jpy; jkpo; ,isQd; xUtu; milahsk; njupahj
MAjjhupfspdhy; Rl;Lf;nfhiy nra;ag;gl;Ls;shu;. Rl;Lf;nfhiy
nra;ag;gl;ltu;&gt; rpj;jhz;b ehtyu; tPjpiar; Nru;e;j kJutPud; Rnu];
<FONT FACE="Bitstream Charter, serif">(suresh)</FONT> (taJ 19) vd
njupate;Js;sJ. jdJ ez;gu;fSld; Js;Se;J xd;wpy; ,d;W tpahof;fpoik fhiy
6.30 kzpf;F nrd;W nfhz;bUe;jNghJ ,j;jhf;Fjy; elj;jg;gl;lJ. mtuJ
rlyj;ij kPl;fr;nrd;w NghJ rlyj;jpw;F mUfpy; Fz;L xd;W fhzg;gl;ljhf
rpwpyq;fh fhty;Jiwapdu; njuptpj;Js;du;. kuz tprhuizfspd; gpd;du; ,d;W
gpw;gfy; RNu]; rlyk; cwtpdu;fsplk; xg;gilf;fg;gl;lJ.</FONT></P>
</BODY>

You can see there are two font varients.

1. <FONT FACE="Bitstream Charter, serif">&&&&&&&&&&&</FONT>

2. <FONT FACE="Bamini">**********</FONT>


the script will search entire html, and will find the pattern <FONT FACE="Bamini">**********</FONT>

and then it will apply this sed command only to the text which situated by "<FONT FACE="Bamini">**********</FONT>" tags (the *****)

Quote:

sed -e 's/—/௮/g' -e 's/•/௬/g' -e 's/‚/ஸ்ரீ/g' < $filename > $filename-tmp-tsc2uni
important thing is, it should not make any changes to other text areas.

acid_kewpie 07-13-2007 04:38 PM

as above. that is what sed is for. this is not special in any way whatsoever...


All times are GMT -5. The time now is 04:43 AM.