#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2010
    Posts
    4
    Rep Power
    0

    Convert a text file in csv using awk


    hi...... thanks for allowing me to start a discussion

    i am collecting usb usage details of all users and convert it into csv files so that i can export it into some database..

    the input text file is as follows:-


    USB History Dump
    by nabiy (c)2008

    (1) --- Kingston DataTraveler 130 USB Device

    instanceID: 0018F3D974B4A9C0E1760896&0
    ParentIdPrefix: 7&b62e00e&2
    Last Mounted As: \DosDevices\I:
    Driver:{4D36E967-E325-11CE-BFC1-08002BE10318}\0033
    Disk Stamp: 09/07/2010 15:07
    Volume Stamp: 09/07/2010 15:07

    (2) --- Kingston DataTraveler 2.0 USB Device

    instanceID: 001D0F1E35B25B8C1201011B&0
    ParentIdPrefix: 7&1f5848f3&0
    Driver:{4D36E967-E325-11CE-BFC1-08002BE10318}\0035
    Disk Stamp: 09/06/2010 15:18
    Volume Stamp: 09/06/2010 15:18

    (3) --- Maxtor OneTouch III USB Device

    instanceID: 044303E5&0
    ParentIdPrefix:
    Driver:{4D36E967-E325-11CE-BFC1-08002BE10318}\0032
    Disk Stamp: 09/10/2010 10:09
    Volume Stamp: 03/12/2010 10:42

    how can i parse this file so that i can get in following format

    hostname, Devic_name, instanceID, ParentPrefix,lastmt t
    pcname kingston 001xxxx 7&b62 DosDevices xxxx
    pcname maxtor 0440 367 Dis devices xxxx


    the output desirable is in csv format for database with some batch or awk script........
    any suggestion in this regard is greatly appreciated
    thanks in advance/.........
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2007
    Posts
    765
    Rep Power
    929
    What have you tried, where are you stuck?

    Though this certainly is within awk's capabilities, you might find it easier to work with (and get assistance with) perl.

    If you need a place to start, look at the 'RS' and 'FS' variables. The simplest way to approach this is to read all the data about a device at once.
    sub{*{$::{$_}}{CODE}==$_[0]&& print for(%:: )}->(\&Meh);
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2010
    Posts
    4
    Rep Power
    0

    tried with awk


    i will try with awk,................. as per perl.///////// i m unfamiliar......

    i ll get back to u soon//////////
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2007
    Posts
    765
    Rep Power
    929
    Originally Posted by certteam
    i will try with awk,................. as per perl.///////// i m unfamiliar......

    i ll get back to u soon//////////
    Also, please try to cut back on the punctuation, texting-speak and so on, it makes it difficult to understand. Obligatory link to How to ask questions the smark way <--- click link and read
    sub{*{$::{$_}}{CODE}==$_[0]&& print for(%:: )}->(\&Meh);

IMN logo majestic logo threadwatch logo seochat tools logo