Re: need help with awk
On Tue, Oct 06, 2009 at 04:41:43PM +0200, Guillaume CHARDIN wrote:
> Hi,
>
> In a backup process of some xen virtual machine, i need to extract in
> the config file some informations (in fact the disk line) .
> The line look like this :
> disk = [ file:/path/to/file,sda1,w ]
> my goal is to isolate le `file` part to use it later. I'm a beginner
> with sed/grep and i dont know it its possible to just extract the part
> between two given regexp. With awk its possible to extract LINES from
> a file with this syntax `awk "/firstFoundRegexp/,/secondRegexp/"`
> this kind of behavior can be applied on one file ?
To extract the file name:
echo disk = [ file:/path/to/file,sda1,w ]|awk 'BEGIN { FS = "[/,]"; } { print $4}'
As for processing only between some lines, you can try this:
<code>
BEGIN { proces_line = 0; }
/startprocessing_regexp/ { process_line = 1 }
process_line {
/* Do stuff */
}
/stopprocessing_regexp/ { process_line = 1; }
</code>
Far from elegant, but will work (I think).
HTH.
Kumar
Reply to: