LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 07-13-2007, 01:28 PM   #1
mauran
LQ Newbie
 
Registered: Dec 2005
Location: Sri Lanka
Distribution: unbuntu 7.04
Posts: 17

Rep: Reputation: 0
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?
 
Old 07-13-2007, 01:36 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,384

Rep: Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963
well that's the point of sed...

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

should do it as an example.
 
Old 07-13-2007, 02:05 PM   #3
mauran
LQ Newbie
 
Registered: Dec 2005
Location: Sri Lanka
Distribution: unbuntu 7.04
Posts: 17

Original Poster
Rep: Reputation: 0
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.
 
Old 07-13-2007, 02:38 PM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
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.
 
Old 07-13-2007, 02:39 PM   #5
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,384

Rep: Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963
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
 
Old 07-13-2007, 02:47 PM   #6
mauran
LQ Newbie
 
Registered: Dec 2005
Location: Sri Lanka
Distribution: unbuntu 7.04
Posts: 17

Original Poster
Rep: Reputation: 0
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.
 
Old 07-13-2007, 04:38 PM   #7
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,384

Rep: Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963
as above. that is what sed is for. this is not special in any way whatsoever...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
SED - replace text in file on specific line 3saul Linux - Software 1 03-04-2006 07:01 PM
SED - display text on specific line of text file 3saul Linux - Software 3 12-29-2005 04:32 PM
How to find and change a specific text in a text file by using shell script Bassam Programming 1 07-18-2005 07:15 PM
[bash] cutting text with sed Erhnam Programming 3 02-11-2005 04:31 AM
bash-script: output text between two ocurrences of a specific string isl01jbe Programming 1 06-17-2004 02:36 PM


All times are GMT -5. The time now is 10:34 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration