sed Question! <sec>

sed Question! <sec>

Post by s.. » Tue, 21 Nov 2000 04:00:00



This works on some OS's, but not all.  No errors occur, but the
substitution doesn't happen:

#!/bin/sh
USER=Andrew
DATE=`date`
sed "s!\(^[ ]*/usr/sbin/in\.routed -q\)!\# \
Commented by ${USER} on ${DATE}\\
#\1!" /tmp/inetinit

This works on all OS's I've tried:

#!/bin/sh

USER=Andrew
DATE=`date`
sed "s!^\([ ]*/usr/sbin/in\.routed -q\)!\# \
Commented by ${USER} on ${DATE}\\
#\1!" /tmp/inetinit

The only difference is the placement of the caret on line 4.

I am curious why!  Comments?

 
 
 

sed Question! <sec>

Post by Eric Amic » Tue, 21 Nov 2000 04:00:00



> This works on some OS's, but not all.  No errors occur, but the
> substitution doesn't happen:

> #!/bin/sh
> USER=Andrew
> DATE=`date`
> sed "s!\(^[ ]*/usr/sbin/in\.routed -q\)!\# \
> Commented by ${USER} on ${DATE}\\
> #\1!" /tmp/inetinit

> This works on all OS's I've tried:

> #!/bin/sh

> USER=Andrew
> DATE=`date`
> sed "s!^\([ ]*/usr/sbin/in\.routed -q\)!\# \
> Commented by ${USER} on ${DATE}\\
> #\1!" /tmp/inetinit

> The only difference is the placement of the caret on line 4.

> I am curious why!  Comments?

I suspect it's because the latter makes it clear that the caret anchors
the regular expression.  I'm not sure if POSIX or any other standard
states that the \( sequence should be ignored when determining whether
the regular expression begins with a caret, though it seems much simpler
to me to require anchoring characters like ^ and $ to be outside \(...\)
sequences.  The ones that don't make the substitution with the first RE
are probably treating the caret as regular text.

--
Eric Amick
Columbia, MD


 
 
 

sed Question! <sec>

Post by Geoff Clar » Thu, 23 Nov 2000 04:00:00




>  I'm not sure if POSIX or any other standard
>states that the \( sequence should be ignored when determining whether
>the regular expression begins with a caret, though it seems much simpler
>to me to require anchoring characters like ^ and $ to be outside \(...\)
>sequences.

POSIX allows systems to behave either way.  To be portable to both
types, you have to use:

    /^\(...\)/ if you want the ^ to be an anchor,
and:
    /\(\^...\)/ if you want the ^ to match a real ^ character.

--


 
 
 

1. <><><> MOUNTING EXTENDED PARTITION <><><>

I have a 10 GB UDMA IDE drive formatted with Windows.  The first partition
is FAT32, and the second is NTFS.  I can successfully mount the first, but
not the second.  Any ideas?

Suse 7.2 on i86
the drive is mounted on /dev/hdc, and I CAN see hda1, but not hda2

2. HP Vectra install fails

3. Wanted: <><><> Unix Specialist <><><>

4. Network Printer

5. LILO help <><><><><><>

6. MULTICS and the Jargon File

7. SED Question << >>

8. 25 Linux Workstations. Pros/Cons?

9. <Alt>+<key> = <Esc><key> ?

10. *{<><>}*Linux*Screen*Difficulties*{<><>}*

11. << <<anyone using dyn-html?>> >>

12. (<><>)*Linux*Screen*Difficulties*(<><>)

13. Samba problem: WinXP <-> ADSL <-> Internet <-> Cable <-> Linux