using sed and apache

using sed and apache

Post by IrieIa » Sat, 21 Dec 2002 04:09:40



Hello group

I've got a text file that I need to sed words that contain a '-' need to
have html
font tags added to. (negative numbers to be colored red)  This will work in
an apache
dir indexing env where as each .txt file is requested, the server will write
the httpd headers,
html head and footer and stick the .txt in the middle - w/no formatting)

Is this possible, does my question make sense?

TIA
--
-IrieIam

 
 
 

using sed and apache

Post by IrieIa » Sat, 21 Dec 2002 06:24:09


Update to question:

This is what I'm trying (and failing with)

sed s/*.\-/\<font color\=\'red\'\>&\<\/font\> G01trn.txt >G01trn2.txt

and this is the error:

[1] 8532
sed: -e expression #1, char 11: Unterminated `s' command
bash: </font>: No such file or directory
[1]+  Exit 1                  sed s/*.\-/\</font color\=\'red\'\>

I'm searching for strings like:    49005-
and would like to it to re-appear as:    <font color='red'>49005-</font>

also, _any_ string that has the '-' should be converted so there won't be
any
mis-understandings ;)

Thanks again!
--
-IrieIam


Quote:> Hello group

> I've got a text file that I need to sed words that contain a '-' need to
> have html
> font tags added to. (negative numbers to be colored red)  This will work
in
> an apache
> dir indexing env where as each .txt file is requested, the server will
write
> the httpd headers,
> html head and footer and stick the .txt in the middle - w/no formatting)

> Is this possible, does my question make sense?

> TIA
> --
> -IrieIam


 
 
 

using sed and apache

Post by Barry Margoli » Sat, 21 Dec 2002 04:56:21




>Update to question:

>This is what I'm trying (and failing with)

>sed s/*.\-/\<font color\=\'red\'\>&\<\/font\> G01trn.txt >G01trn2.txt

>and this is the error:

>[1] 8532
>sed: -e expression #1, char 11: Unterminated `s' command

You're missing the third / in the s/old/new/ command.

Quote:>bash: </font>: No such file or directory

You forgot to escape the '&', so it's being processed by the shell as a
command delimiter (it's like ';', except that it runs the preceding command
in the background).  You could make things alot easier if you put the whole
sed argument in quotes, rather than escaping individual characters:

sed "s/*.-/<font color='red'>&<\/font>/" G01trn.txt > G01trn2.txt

Another thing that worries me is the '*.-' in your old pattern.  That will
match the literal character '*' (because '*' is only special in regular
expressions when it follows another expression), followed by any character,
followed by the literal character '-'.  Did you mean '.*-', which matches
any sequence of characters followed by a literal '-'?

--

Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

 
 
 

using sed and apache

Post by IrieIa » Sat, 21 Dec 2002 06:55:40





> >Update to question:

> >This is what I'm trying (and failing with)

> >sed s/*.\-/\<font color\=\'red\'\>&\<\/font\> G01trn.txt >G01trn2.txt

> >and this is the error:

> >[1] 8532
> >sed: -e expression #1, char 11: Unterminated `s' command

> You're missing the third / in the s/old/new/ command.

> >bash: </font>: No such file or directory

> You forgot to escape the '&', so it's being processed by the shell as a
> command delimiter (it's like ';', except that it runs the preceding
command
> in the background).  You could make things alot easier if you put the
whole
> sed argument in quotes, rather than escaping individual characters:

> sed "s/*.-/<font color='red'>&<\/font>/" G01trn.txt > G01trn2.txt

I did notice that in another thread and quoted the whole cmd (but with
single quotes because the ="red" must be double) did i _have_ to do that?

Quote:> Another thing that worries me is the '*.-' in your old pattern.  That will
> match the literal character '*' (because '*' is only special in regular
> expressions when it follows another expression), followed by any
character,
> followed by the literal character '-'.  Did you mean '.*-', which matches
> any sequence of characters followed by a literal '-'?

I see...
Changed it to
 sed 's/[0-9*].-/\<font color\=\"red\"\>&\<\/font\>/' G01trn.txt
Quote:>G01trn2.txt

and it works, but only replaces the '1st' match in each line.  I'm looking
around
for the way to make it keep replaceing multiple matches on on line...

Thanks for the help Barry,

-IrieIam

> --

> Genuity, Woburn, MA
> *** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to
newsgroups.
> Please DON'T copy followups to me -- I'll assume it wasn't posted to the

group.
 
 
 

using sed and apache

Post by IrieIa » Sat, 21 Dec 2002 06:57:24


BTW, escaping the '&' is not necessary

--
-IrieIam





> > >Update to question:

> > >This is what I'm trying (and failing with)

> > >sed s/*.\-/\<font color\=\'red\'\>&\<\/font\> G01trn.txt >G01trn2.txt

> > >and this is the error:

> > >[1] 8532
> > >sed: -e expression #1, char 11: Unterminated `s' command

> > You're missing the third / in the s/old/new/ command.

> > >bash: </font>: No such file or directory

> > You forgot to escape the '&', so it's being processed by the shell as a
> > command delimiter (it's like ';', except that it runs the preceding
> command
> > in the background).  You could make things alot easier if you put the
> whole
> > sed argument in quotes, rather than escaping individual characters:

> > sed "s/*.-/<font color='red'>&<\/font>/" G01trn.txt > G01trn2.txt

> I did notice that in another thread and quoted the whole cmd (but with
> single quotes because the ="red" must be double) did i _have_ to do that?

> > Another thing that worries me is the '*.-' in your old pattern.  That
will
> > match the literal character '*' (because '*' is only special in regular
> > expressions when it follows another expression), followed by any
> character,
> > followed by the literal character '-'.  Did you mean '.*-', which
matches
> > any sequence of characters followed by a literal '-'?

> I see...
> Changed it to
>  sed 's/[0-9*].-/\<font color\=\"red\"\>&\<\/font\>/' G01trn.txt
> >G01trn2.txt
> and it works, but only replaces the '1st' match in each line.  I'm looking
> around
> for the way to make it keep replaceing multiple matches on on line...

> Thanks for the help Barry,

> -IrieIam

> > --

> > Genuity, Woburn, MA
> > *** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to
> newsgroups.
> > Please DON'T copy followups to me -- I'll assume it wasn't posted to the
> group.

 
 
 

using sed and apache

Post by IrieIa » Sat, 21 Dec 2002 07:03:02


ah haa...

I just found the 'g' global option.  sweet.
--
-IrieIam






> > >Update to question:

> > >This is what I'm trying (and failing with)

> > >sed s/*.\-/\<font color\=\'red\'\>&\<\/font\> G01trn.txt >G01trn2.txt

> > >and this is the error:

> > >[1] 8532
> > >sed: -e expression #1, char 11: Unterminated `s' command

> > You're missing the third / in the s/old/new/ command.

> > >bash: </font>: No such file or directory

> > You forgot to escape the '&', so it's being processed by the shell as a
> > command delimiter (it's like ';', except that it runs the preceding
> command
> > in the background).  You could make things alot easier if you put the
> whole
> > sed argument in quotes, rather than escaping individual characters:

> > sed "s/*.-/<font color='red'>&<\/font>/" G01trn.txt > G01trn2.txt

> I did notice that in another thread and quoted the whole cmd (but with
> single quotes because the ="red" must be double) did i _have_ to do that?

> > Another thing that worries me is the '*.-' in your old pattern.  That
will
> > match the literal character '*' (because '*' is only special in regular
> > expressions when it follows another expression), followed by any
> character,
> > followed by the literal character '-'.  Did you mean '.*-', which
matches
> > any sequence of characters followed by a literal '-'?

> I see...
> Changed it to
>  sed 's/[0-9*].-/\<font color\=\"red\"\>&\<\/font\>/' G01trn.txt
> >G01trn2.txt
> and it works, but only replaces the '1st' match in each line.  I'm looking
> around
> for the way to make it keep replaceing multiple matches on on line...

> Thanks for the help Barry,

> -IrieIam

> > --

> > Genuity, Woburn, MA
> > *** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to
> newsgroups.
> > Please DON'T copy followups to me -- I'll assume it wasn't posted to the
> group.

 
 
 

using sed and apache

Post by Barry Margoli » Sat, 21 Dec 2002 05:24:34






>> sed "s/*.-/<font color='red'>&<\/font>/" G01trn.txt > G01trn2.txt

>I did notice that in another thread and quoted the whole cmd (but with
>single quotes because the ="red" must be double) did i _have_ to do that?

I think HTML allows either single or double quotes in its
<attribute>=<value> parameters.  Since your original version put single
quotes around red, I kept it that way and put double quotes around the
whole argument.  It works the other way around also.

Quote:>> Another thing that worries me is the '*.-' in your old pattern.  That will
>> match the literal character '*' (because '*' is only special in regular
>> expressions when it follows another expression), followed by any
>character,
>> followed by the literal character '-'.  Did you mean '.*-', which matches
>> any sequence of characters followed by a literal '-'?

>I see...
>Changed it to
> sed 's/[0-9*].-/\<font color\=\"red\"\>&\<\/font\>/' G01trn.txt
>>G01trn2.txt

Is /[0-9*].-/ really right?  That matches a single digit or "*", followed
by any character, followed by "-".  Don't you want to match the entire
number, not just a single digit?  And what's the "*" doing inside the
character set match?  Did you mean /[0-9]*-/?

--

Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

 
 
 

using sed and apache

Post by John Gordo » Sat, 21 Dec 2002 04:47:53



> I've got a text file that I need to sed words that contain a '-'
> need to have html font tags added to. (negative numbers to be colored

*any* word containing "-"?  or just numbers?

Quote:> red)  This will work in an apache dir indexing env where as each
> .txt file is requested, the server will write the httpd headers,
> html head and footer and stick the .txt in the middle - w/no
> formatting)

if you really want the server itself to execute the sed and deliver
the results, you've got a lot of work ahead of you.  mucking with
apache server code is not for the faint of heart.  good luck.

instead, could you edit each .txt file ahead of time to insert
the desired codes?  that would be MUCH easier.

---
John Gordon                  "No Silicon Heaven?  Preposterous!  Where would

 
 
 

using sed and apache

Post by IrieIa » Sat, 21 Dec 2002 06:19:35


This is what I have working (quite well too)

sed 's/[0-9].[0-9]*-/\<font color\=\"red\"\>&\<\/font\>/g' G01trn.html

Quote:>G01trn2.html

The . gets 'fractions' and 'thousands'.
That gets the lines i need and _not_ the lines like '--------', which are
many!

So, thats that!

Much Thanks,
--
-IrieIam






> >> sed "s/*.-/<font color='red'>&<\/font>/" G01trn.txt > G01trn2.txt

> >I did notice that in another thread and quoted the whole cmd (but with
> >single quotes because the ="red" must be double) did i _have_ to do that?

> I think HTML allows either single or double quotes in its
> <attribute>=<value> parameters.  Since your original version put single
> quotes around red, I kept it that way and put double quotes around the
> whole argument.  It works the other way around also.

> >> Another thing that worries me is the '*.-' in your old pattern.  That
will
> >> match the literal character '*' (because '*' is only special in regular
> >> expressions when it follows another expression), followed by any
> >character,
> >> followed by the literal character '-'.  Did you mean '.*-', which
matches
> >> any sequence of characters followed by a literal '-'?

> >I see...
> >Changed it to
> > sed 's/[0-9*].-/\<font color\=\"red\"\>&\<\/font\>/' G01trn.txt
> >>G01trn2.txt

> Is /[0-9*].-/ really right?  That matches a single digit or "*", followed
> by any character, followed by "-".  Don't you want to match the entire
> number, not just a single digit?  And what's the "*" doing inside the
> character set match?  Did you mean /[0-9]*-/?

> --

> Genuity, Woburn, MA
> *** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to
newsgroups.
> Please DON'T copy followups to me -- I'll assume it wasn't posted to the

group.
 
 
 

using sed and apache

Post by Barry Margoli » Sat, 21 Dec 2002 07:08:04




>This is what I have working (quite well too)

>sed 's/[0-9].[0-9]*-/\<font color\=\"red\"\>&\<\/font\>/g' G01trn.html
>>G01trn2.html

>The . gets 'fractions' and 'thousands'.

Didn't you say this was for negative numbers?  Why is the "-" at the end
instead of the beginning?  Is this just something weird about the way
numbers are formatted in this file?

Regarding the fractions and thousands thing, I assume you're talking about
commas and decimal points.  But you're only recognizing a single digit
before them.  What about something like 123,456- or 123.456-?  The redness
will only start at the 3, not at the beginning of the number number.  I
think you want something like:

sed 's/[0-9,.][0-9,.]*-/.../'

--

Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

 
 
 

using sed and apache

Post by IrieIa » Sat, 21 Dec 2002 14:18:55





> >This is what I have working (quite well too)

> >sed 's/[0-9].[0-9]*-/\<font color\=\"red\"\>&\<\/font\>/g' G01trn.html
> >>G01trn2.html

> >The . gets 'fractions' and 'thousands'.

> Didn't you say this was for negative numbers?  Why is the "-" at the end
> instead of the beginning?  Is this just something weird about the way
> numbers are formatted in this file?

They are reports generated by an unrelated (and uncontrolable) program.
Actually, with columns of text, the '-' is easier to see when columns are
aligned to the right. like:

41,224-
56-
19.2-

sucks but:

41,224-
       56-
    19.2-

is much easier to see ;)

Quote:> Regarding the fractions and thousands thing, I assume you're talking about
> commas and decimal points.  But you're only recognizing a single digit
> before them.  What about something like 123,456- or 123.456-?  The redness
> will only start at the 3, not at the beginning of the number number.  I
> think you want something like:

> sed 's/[0-9,.][0-9,.]*-/.../'

I'll try that.  I think you're right.

thanks

-IrieIam

> --

> Genuity, Woburn, MA
> *** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to
newsgroups.
> Please DON'T copy followups to me -- I'll assume it wasn't posted to the

group.
 
 
 

using sed and apache

Post by Peter Jone » Sat, 21 Dec 2002 16:15:33



> I've got a text file that I need to sed words that contain a '-' need to
> have html
> font tags added to. (negative numbers to be colored red)  This will work in
> an apache
> dir indexing env where as each .txt file is requested, the server will write
> the httpd headers,
> html head and footer and stick the .txt in the middle - w/no formatting)

you can use mod_sed, but like others have said, it is probably better to
do this to the file before you place it under apache.

http://www.happygiraffe.net/mod_sed.html

--
Peter Jones <unix;c++;crypto;vi;4wd;geek> [ http://pmade.org ]

 
 
 

using sed and apache

Post by IrieIa » Sun, 22 Dec 2002 12:28:45


thx for link.

i'll check it out.

--
-IrieIam



> > I've got a text file that I need to sed words that contain a '-' need to
> > have html
> > font tags added to. (negative numbers to be colored red)  This will work
in
> > an apache
> > dir indexing env where as each .txt file is requested, the server will
write
> > the httpd headers,
> > html head and footer and stick the .txt in the middle - w/no formatting)

> you can use mod_sed, but like others have said, it is probably better to
> do this to the file before you place it under apache.

> http://www.happygiraffe.net/mod_sed.html

> --
> Peter Jones <unix;c++;crypto;vi;4wd;geek> [ http://pmade.org ]

 
 
 

1. sed problem: using sed in a shell script

I am having a very odd problem. The following command is not working
in my shell script:

#!/bin/sh
# snip code #
sed "$start_line,$end_line""d" $1.tmp > $1.new
# END snip #

But, it _does_ work if i enter it at the command-line:
[eve]$  set start_line=2 ; set end_line=4 ; \
sed "$start_line,$end_line""d" tokenize_line.c.tmp > tokenize_line.c.new

This works on the command-line, but not in the script as well:
[eve]$ set start_line=2 ; set end_line=4 ; \
sed "$start_line,${end_line}d" tokenize_line.c.tmp > tokenize_line.c.new

then odd part is that if i set the variables in the script manually,
everything works ok:
#!/bin/sh
# snip #
startline=2; endline=4
sed "$start_line,$end_line""d" $1.tmp > $1.new
# END snip #

so i figured.. there must be space or something before/after the
numbers in the variables. but that is disproved, because i tried this
in the original shell script right before calling sed:
#snip
echo "cutting lines foo${start_line}foo to foo${end_line}foo"
#end snip

and that outputs this (no spaces!):
$
cutting lines foo2foo to foo4foo

so basically, i need to cut line ranges from files, and sed is the
only way i know how to do it, and it dont work (when interpolating
variables) in the shell script. any ideas here? (oh.. my shell is
tcsh)

--
MGatto
Support the anti-spam movement; see <http://www.cauce.org/>

2. Socket -> Pid ?

3. Matrox Mystique ands X.

4. -rwSr-x--- ???

5. Using Sed and Shell Variables in Multiple Lines Search and Replace using /c\

6. Sysadmin Staffing Requirements

7. sed sed sed

8. graPHIGS problem ...

9. . 2 sed FAQs, sed exes, sed cetras; URLs

10. SED SED SED...

11. (sed 1q ; sed 2q) : no output from 2nd 'sed'

12. Different css file depending on which browser is being used using Apache

13. Can Apache be used as a tunnel to another Apache.