parsing text blocks into database - awk
This is a discussion on parsing text blocks into database - awk ; Hello all. I have a file that has multiple lines set up in blocks
that I need to parse out into a file. Is there an easy to get a file
like the one below parsed out. I only need ...
-
parsing text blocks into database
Hello all. I have a file that has multiple lines set up in blocks
that I need to parse out into a file. Is there an easy to get a file
like the one below parsed out. I only need the Slot Address and
Volume Tag info. I would RTFM, but I don't know which to read or how
to decipher what I want to do:
SlotAddress 4096
SlotState.....................Normal
ASC/ASCQ.......................0000
MediaPresent..................Yes
RobotAccessAllowed...........Yes
SourceElementAddress.........4096
MediaInverted.................No
VolumeTag.....................DET028L3
SlotAddress 4097
SlotState.....................Normal
ASC/ASCQ.......................0000
MediaPresent..................Yes
RobotAccessAllowed...........Yes
SourceElementAddress.........4097
MediaInverted.................No
VolumeTag.....................DET029L3
Thanks in advance.
Jim
-
Re: parsing text blocks into database
Hamanjam wrote:
> Hello all. I have a file that has multiple lines set up in blocks
> that I need to parse out into a file. Is there an easy to get a file
> like the one below parsed out. I only need the Slot Address and
> Volume Tag info. I would RTFM, but I don't know which to read or how
> to decipher what I want to do:
You didn't mention what output format you want.
With GNU awk (assuming there are no dots in the volume tag)...
BEGIN { FS="[. ]" }
$1 == "SlotAddress" { sa = $2 }
$1 == "VolumeTag" { print sa, $NF }
The output will be...
4096 DET028L3
4097 DET029L3
Adjust the print output format as you need.
Janis
>
>
>
> SlotAddress 4096
> SlotState.....................Normal
> ASC/ASCQ.......................0000
> MediaPresent..................Yes
> RobotAccessAllowed...........Yes
> SourceElementAddress.........4096
> MediaInverted.................No
> VolumeTag.....................DET028L3
>
> SlotAddress 4097
> SlotState.....................Normal
> ASC/ASCQ.......................0000
> MediaPresent..................Yes
> RobotAccessAllowed...........Yes
> SourceElementAddress.........4097
> MediaInverted.................No
> VolumeTag.....................DET029L3
>
>
> Thanks in advance.
> Jim
>
-
Re: parsing text blocks into database
Thanks Janis!! this is exactly what I needed. I changed the output a
little to have a sql statement so I can drop this into mysql. My
output looks like this now:
insert into slots (slot,volume) values ('4109','DET019L3');
insert into slots (slot,volume) values ('4110','871LLLL3');
My awk script is now:
BEGIN { FS="[. ]" }
$1 == "SlotAddress" { sa = $2 }
$1 == "VolumeTag" { print "insert into slots (slot,volume) values
('"sa"','" $NF "');" }
Similar Threads
-
By Application Development in forum Graphics
Replies: 2
Last Post: 09-22-2007, 05:12 PM
-
By Application Development in forum ADO DAO RDO RDS
Replies: 1
Last Post: 09-21-2007, 12:26 PM
-
By Application Development in forum Adobe Acrobat
Replies: 0
Last Post: 12-20-2006, 01:31 PM
-
By Application Development in forum Inetserver
Replies: 2
Last Post: 05-19-2006, 03:03 PM