Re: Need help with SED


Subject: Re: Need help with SED
From: James McMorris (buddha@gci.net)
Date: Wed May 01 2002 - 15:29:57 AKDT


Sorry, I don't understand what the "escaping newlines" means or what
the pipe does. Here's what I have for the "meat" of my script so far:

#----------------Start Code--------------
#!/bin/sh
sed -e '1421i\
acl SSL_ports port 81 10000' /home/squid.conf > /home/squid.tmp
sed -e '1421i\
acl Safe_ports port 81 10000' /home/squid.tmp > /home/squid.conf
sed -e '1421i\
#SSL connections thru Squid for Webconfig and Webmin' /home/squid.conf
> /home/squid.tmp
sed -e '1421i\
#The following two lines were added to the ACL section to
enable' /home/squid.tmp > /home/squid.conf
sed -e '1421i\
' /home/squid.conf > /home/squid.tmp

cp /home/squid.tmp /home/squid.conf
#--------------End Code--------------------

Two questions:
1) Is there a more efficient way of inserting these lines rather than
copying back-and-forth between these two files?
2) Is my code in the correct "format"? I want to learn the "right" way
the first time. (Visions of spaghetti-code BASIC on a TI-994a from
1982 are dancing in my head. :)

-Jim "Buddha" McMorris

----- Original Message -----
From: "Arthur Corliss" <arthur@corlissfamily.org>
Date: Tuesday, April 30, 2002 7:42 pm
Subject: Re: Need help with SED

>
> > I'm new to bash scripting, so I a little help on getting going
> on a
> > script I'm trying to write. After reading the man pages for
> SED, I
> > can't figure out what command/switch for sed to use to insert
> text
> > at a specific line in a file. I don't want to change anything
> > that's already there, just add two lines of text at line 1422
> of /etc/squid/squid.conf
> >
> > I've already got the code for user input and an "if-then-else"
> setup
> > for execution.
>
> sed '1422a \
> <insert text here, \
> escaping new lines>
> ' squid.conf | new-squid.conf
>
> > Also, is SED the right tool for the job? Or would ED or AWK be
> > better?
> > (Or even PERL, but I don't want to have to learn the basics of
> perl
> > right yet. No offense Arthur :)
>
> Hey, I'll be the first to tell you that Perl isn't perfect for
> everything
> (damn near, though ;-). I still use awk and sed myself.
>
> --
>
> --Arthur Corliss
> Bolverk's Lair -- http://arthur.corlissfamily.org/
> Digital Mages -- http://www.digitalmages.com/
> "Live Free or Die, the Only Way to Live" -- NH State Motto
>
>
> ---------
> To unsubscribe, send email to <aklug-request@aklug.org>
> with 'unsubscribe' in the message body.
>
>

---------
To unsubscribe, send email to <aklug-request@aklug.org>
with 'unsubscribe' in the message body.



This archive was generated by hypermail 2a23 : Wed May 01 2002 - 15:30:01 AKDT