Re: Scripting: awk reg. exp.

From: Green, Simon (Simon.Green@EU.ALTRIA.COM)
Date: Mon Dec 08 2003 - 04:08:43 EST


I'd tried something similar earlier; with it I can exclude commented
out lines. Unfortunately, I want them to appear - unchanged - in
the output and instead they get dropped entirely.

Any other suggestions?

Simon Green
Senior Technical Analyst
Server Management (UNIX Services)

Altria ITSC Europe Ltd
Tel: +44 1242 284318
Fax: +44 1242 284510

> -----Original Message-----
> From: Sunder Iyengar [mailto:Sunder.Iyengar@VERITAS.COM]
> Sent: 05 December 2003 23:32
> To: aix-l@Princeton.EDU
> Subject: Re: Scripting: awk reg. exp.
>
>
> Since you are not interested in lines that are commented out
> with a *, try
> this as a pattern matching string to select only relevant lines:
>
> awk '!/^ *\* */ {sub(....) etc.}'
>
> This should not select any lines that have zero or more
> spaces followed by a
> *, followed by zero or more spaces, at the beginning of the line.
>
<SNIP>
> >>
> >> Hi!
> >> I'm trying to write a little script to automate some changes to
> >> /etc/qconfig: changing certain host names. I've decided to use awk
> >> even though (or perhaps "because") I'm not very familiar with it.
> >>
> >> So far, I've come up with:
> >> {sub(/host = old_name/,"host = new_name");print}
> >> ...and that works fine, except that it will also make changes to
> >> entries which have been commented out, which I would
> prefer to avoid.
> >>
> >> Is there some way of constructing the command so that it does not
> >> select those lines which have been commented out? Remember:
> >> /etc/qconfig uses an
> >> asterisk as a comment-character, which is damn stupid!
>



This archive was generated by hypermail 2.1.7 : Wed Apr 09 2008 - 22:17:23 EDT