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

    Join Date
    Nov 2013
    Posts
    1
    Rep Power
    0

    Extract specific data (user ID) from log file


    I would like to extract the user ID's only from the log file. I have copied the sample code below. All the user ID's are inbetween the text "ID principal: " & ", ". Later i would like to use the data to be copied into an excel sheet to create a chart. Can anybody help me to write a perl script for the same. I have never done some complex task on perl prog till now.
    ---------------------------------------------------------
    Sample log file code:

    Tue Nov 5 09:00:00 2013
    SI Floating Licenses: 14
    ID principal: IDB2COB, ID principal: kdk4oe, ID principal: oij7nde, ID principal: qay8plm, ID principal: wsx9okn, ID principal: LNA6COB, ID principal: lak3kor, ID principal: deveas
    SI Seat Licenses: 7
    ID principal: ISN1COB, ID principal: kao7wbe, ID principal: kor4sds, ID principal: HSC4WE, ID principal: usr4cint, ID principal: SUU4COB, ID principal: birr
    IM Floating Licenses: 8
    ID principal: tram2we, ID principal: IDB2COB, ID principal: kao7wbe, ID principal: HSC4WE, ID principal: VBN1KOR, ID principal: adf3rtz, ID principal: MAG4KOR, ID principal: ASI3COB
    IM Seat Licenses: 2
    ID principal: kor4sds, ID principal: ribbs


    Tue Nov 5 09:30:00 2013
    SI Floating Licenses: 10
    ID principal: IDB2COB, ID principal: kdk4oe, ID principal: oij7nde, ID principal: qay8plm, ID principal: wsx9okn, ID principal: LNA6COB, ID principal: lak3kor, ID principal: deveas
    SI Seat Licenses: 7
    ID principal: ISN1COB, ID principal: kao7wbe, ID principal: kor4sds, ID principal: HSC4WE, ID principal: usr4cint, ID principal: SUU4COB, ID principal: birr
    IM Floating Licenses: 8
    ID principal: tram2we, ID principal: IDB2COB, ID principal: kao7wbe, ID principal: HSC4WE, ID principal: VBN1KOR, ID principal: adf3rtz, ID principal: MAG4KOR, ID principal: ASI3COB
    IM Seat Licenses: 2
    ID principal: kor4sds, ID principal: ribbs


    Tue Nov 5 10:00:00 2013
    SI Floating Licenses: 7
    ID principal: IDB2COB, ID principal: kdk4oe, ID principal: oij7nde, ID principal: qay8plm, ID principal: wsx9okn, ID principal: LNA6COB, ID principal: lak3kor, ID principal: deveas
    SI Seat Licenses: 7
    ID principal: ISN1COB, ID principal: kao7wbe, ID principal: kor4sds, ID principal: HSC4WE, ID principal: usr4cint, ID principal: SUU4COB, ID principal: birr
    IM Floating Licenses: 8
    ID principal: tram2we, ID principal: IDB2COB, ID principal: kao7wbe, ID principal: HSC4WE, ID principal: VBN1KOR, ID principal: adf3rtz, ID principal: MAG4KOR, ID principal: ASI3COB
    IM Seat Licenses: 2
    ID principal: kor4sds, ID principal: ribbs
    -----------------------------------------------------------
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Posts
    836
    Rep Power
    496
    You could use a regex to retrieve the IDs. Assuming your record is in the $_ special variable, something like this:

    Perl Code:
    @matches =~ /ID principal:\s+(\w+),/g;


    would store the various matching IDs into the @matches array.

IMN logo majestic logo threadwatch logo seochat tools logo