Re: Another sed problem...

From: rakesh sharma (sharma__r_at_hotmail.com)
Date: 11/20/03


Date: 20 Nov 2003 11:11:07 -0800

greyfell@zerobyte.org wrote in message news:<b0oprvk2nk1cu8shg2ngfis9ic7uuhq5g4@4ax.com>...
> I'm trying to do a find and replace in sed. I'm pretty sure my problem
> is that some of the characters I'm replacing with are reserved
> characters for sed. I've tried both of these incarnations...
>
> sed -e "s/webserv .*\$/webserv !(dst host web1) or port ftp or port
> ftp-data or port 80 or port 433/g" </etc/pf.d/IP/net0
> >/etc/pf.d/IP/net0.mod
>
> sed -e 's/webserv .*$/webserv !(dst host web1) or port ftp or port
> ftp-data or port 80 or port 433/g' </etc/pf.d/IP/net0
> >/etc/pf.d/IP/net0.mod
>
> No luck with either. I just want to repace any line beginning with
> webserv (even if it is the first line), and replace it with...
>
> webserv !(dst host web1) or port ftp or port ftp-data or port 80 or
> port 433/g' </etc/pf.d/IP/net0
>
> Any help greatly appreciated. Thanks in advance.

If your shell is c-shell or it's derivative then we need to escape
the ! from the shell or use the 'sed -f' option. the -f option is
useful when u don't want the shell to cast any evil glances on your
sed commands lines.

sed -e '
/webserv/s/.*/webserv \!(dst host web1) or port ftp or port ftp-data
or port 80 or port 433/
' /etc/pf.d/IP/net0

## note: no need of the '/g' option as you are replacing the whole
line in one fell swoop.

or, put the following line in a file(say 'cmdfile') and
have sed use that for it's commands:

/webserv/s/.*/webserv !(dst host web1) or port ftp or port ftp-data or
port 80 or port 433/

then invoke sed as:

sed -f cmdfile /etc/pf.d/IP/net0



Relevant Pages

  • Re: Another sed problem...
    ... > is that some of the characters I'm replacing with are reserved ... assuming you want to keep whatever is after webserv then this will do the trick ... or port 80 or port 433/g' ...
    (comp.unix.shell)
  • Re: Serial COM port communication problems
    ... serial port. ... The receiving buffer is read by setting the mask to rx flag being the ... sub-packages arrive in succession and some sub-packages are lost. ... But this should not cause a loss of data, assuming you are reading the actual number of characters retured by WaitCommEvent. ...
    (microsoft.public.win32.programmer.kernel)
  • Re: Cycling to school - draft.
    ... At the moment it is about 80 characters per line which is perfect for two ... I'd advise avoiding it and replacing with a ... semi-bold or bold weight. ... Keep up the brilliant work. ...
    (uk.rec.cycling)
  • Re: [PATCH: 2/2] [SERIAL] avoid stalling suspend if serial port wont drain
    ... prefer - the system being prevented from suspending and losing complete ... The only way you could do that on 8250 is to clear the RX FIFO, ... wait for the port to transmit all its characters into the RX ...
    (Linux-Kernel)
  • Re: Read/Write to file
    ... > whole data in one file and just replace characters. ... file and then replacing the old one with it tends to be simpler). ... You will probably have to do that manually, i.e. reading in lines, ... for the line count and increment it after each successful fgets(). ...
    (comp.lang.c)