Re: need help with awk
On Tue, Oct 06, 2009 at 06:27:12PM +0200, Guillaume CHARDIN wrote:
> Thanks for your reply Kumar,
You're welcome.
> ><code>
> >BEGIN { proces_line = 0; }
> >
> >/startprocessing_regexp/ { process_line = 1 }
> >
> >process_line {
> > /* Do stuff */
> >}
> >
> >/stopprocessing_regexp/ { process_line = 1; }
> >
>
> I'm not familiar with the syntax you usei'm gonna look at it soon, but
> for sure your method is less ugly than mine.
Sure.
> But for today, I finaly get bored and used a successive usage of "
> | "s :-D. Now the code is nearly unreadable if you don't read it
> carefully but it works !
>
> #echo disk = [ file:/path/to/file,sda1,w ] | awk -F= '{print $2}' |
> awk -F[ '{print $2}' | awk -F= '{print $1}' | awk -F, '{print $1}' |
> awk -F: '{print $2}'
> /path/to/file
Oh, if this is what you wanted, I was wrong. You can sum up the
previous pipes into:
echo disk = [ file:/path/to/file,sda1,w ] | awk 'BEGIN { FS = "[:,]" } { print $2 }'
> The point is if i have more than one `disk` argument, i'll have to
> find a way to identify each of them... But lets keep some work for
> tomorrow :)
I think your program should be as simple as:
<code>
#!/usr/bin/awk -f
BEGIN { FS = "[:,]" }
/disk *=/ { print $2 }
</code>
Put this in myprog.awk, and chmod +x it, and run ./myprog.awk <configfile>.
This will only list such entries, not substitute though.
HTH.
Kumar
Reply to: