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


--
To UNSUBSCRIBE, email to debian-user-REQUEST@xxxxxxxxxxxxxxxx
with a subject of "unsubscribe". Trouble? Contact listmaster@xxxxxxxxxxxxxxxx



Relevant Pages

  • Re: minidrive: Spinning up disk ... .not responding ...
    ... Subject: minidrive: Spinning up disk ... ... I need to extract the data from a ... To UNSUBSCRIBE, email to debian-user-REQUEST@xxxxxxxxxxxxxxxx ... Trouble? ...
    (Debian-User)
  • need help with awk
    ... the config file some informations (in fact the disk line). ... with sed/grep and i dont know it its possible to just extract the part ... To UNSUBSCRIBE, email to debian-user-REQUEST@xxxxxxxxxxxxxxxx ...
    (Debian-User)
  • Re: File extraction problem
    ... from a DOS 3.3 format disk. ... The file I was trying to extract is "QLISTER.ABS". ... Apple II programs available. ... DUMPFILES is the required switch to create disk files. ...
    (comp.sys.apple2)
  • DBXpress CANNOT extract from Disk to the same Disk
    ... DBXpress CANNOT extract from Disk to the same Disk ... Can DBXpress extract from Disk to the same Disk? ... Subject: Warning: DBXpress recovery program ...
    (microsoft.public.windows.inetexplorer.ie6_outlookexpress)
  • CD Automount problem
    ... For some time I have been using sound juicer to extract tunes to my ... I recently tried to extract from a CD that had a multimedia component. ... there) and pushing the eject button on the drive did nothing. ... ended up shutting down to eject the disk. ...
    (Ubuntu)