Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Perl Extract specific string

by CountZero (Bishop)
on Feb 09, 2013 at 08:22 UTC ( #1017934=note: print w/ replies, xml ) Need Help??


in reply to Perl Extract specific string

Before we answer we need some more info.

  • Are these three lines of data actually ONE line or indeed THREE lines? Tip: enclose your data in <code> ... </code> tags. That makes it easier to see the actual format and also things like square brackets and such.
  • Can you show some more lines of your data? Especially when you have to write perhaps a regular expression to extract the data it is always good to see some more data, to check how "regular" your data structure really is.

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

My blog: Imperial Deltronics


Comment on Re: Perl Extract specific string
Download Code
Re^2: Perl Extract specific string
by MacLing (Novice) on Feb 09, 2013 at 13:17 UTC

    Hi CountZero,

    It One line. and structure data is same. and there is a lots of data in each file.

    anyway thanks for your reply, i will test it. Please give me the script which can read from input file and create the output file

      Perl is such a powerful language, you only need a few lines of code:
      use Modern::Perl; while (<DATA>) { my ( $date, $msisdn, $ud, $trxtime, $response ) = map { /:([^:]+)/ ? $1 : $_ } ( split /[\s+,]/ )[ 0, 6, 7, 8, 11 +]; say join ',', $date, $msisdn, $ud, substr( $trxtime, 0, 8 ), $resp +onse; } __DATA__ 06.02.2013 12.24.01:909 5807225321 INFO {EXT:httpadapter:17:14:}[0]RUL +EZ [HTTPADAPTER],msisdn:637584930382,ud:Pan,trxtime:20130206122401 Re +sponseDeltaTime:31 ms ResponseCode:200 ResponseBody:OK
      Output:
      06.02.2013,637584930382,Pan,20130206,200

      CountZero

      A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

      My blog: Imperial Deltronics

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1017934]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (12)
As of 2014-11-26 02:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (160 votes), past polls