regex - How to extract a part of line in perl -


I would like to know how to extract a part of a line from a file in Perl. I have a log file from which I want to remove some meaningful information through a Perl script. I was able to get the full line I was looking for, but I only want one part of that line.

Perl script (I used):

  #! Use / usr / bin / perl strict; Use warnings; My $ file = 'F: \ 3Np_RoboSitter \ perl pgm \ input.txt'; Open your $ FH, "$ lt;", $ file or $$! Print "************************************************************************************************** ************************************************************************************************ ******** \ n "; Print "DC status: \ n \ n"; While (& lt; $ fh & gt;) {Print / DC message / / / DC messages selected from Qualified; } Print "\ n ******************************************************************************* ************************************************************************************************* ************************************ "; Closed ($ FH);   

Input file:

  adfaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaadfafafafqdrareeaf 2014-02-14 00: 18: 04,840 1754897056 INFO Application Services aadfafa123 Application Services Service ApplicationDateCustomerID ApplicationServiceSessionToken XML of Pars started. | Hostname = AAAAAA | Timestamp = 2014-02-14 00: 16: 39.044 | Message = out; SubmitApplications.SubmitApplicationBatchProcess; Total 1311 DC messages were selected from the queue. Extension = & lt; XMLNSC & gt; & Lt; LogMessage & gt; & Lt; MessageText>. A total of 1311 DC messages were taken from the queue. & Lt; / MessageText> gt; & Lt; / Logmessage & gt; & Lt; / XMLNSC & gt; dafafafzcvzvsfdfafafffffffffffffffffffffffff   

Output:

  ************************** ***************** DC status: 2014-02-14 00: 18: 04,840 1754897056 INFO ApplicationService Aidfafa 123 began parsing the Anupryogsewayrssewa Kstmraidi Anupryogsewasesesotiotikaksaksaksaks. | Hostname = AAAAAA | Timestamp = 2014-02-14 00: 16:. 39.0 44 Message = out; SubmitApplications.SubmitApplicationBatchProcess; Total 1311 DC I selected from the queue ssages | Extension = & lt; XMLNSC & gt; & Lt; LogMessage & gt; & Lt; Message text & gt; A total of 1311 DC messages were taken from the queue. & Lt; / MessageText> gt; & Lt; / Logmessage & gt; & Lt; / XMLNSC & gt; **************************************************************************************************** *********   

desired output:

  2014-02-14 00:18:04 Total 1311 DC message queue. * Provide (that & lt; messagetext & gt; between the tags) *   

team, please ur valuable suggestions to get your free moment! ...

It is always based on input your input is not well formatted (not fixed) Length, not CSV) to be the easiest Regedix method.

  while (my $ line = <$ fh> gt;) {my ($ date)) = partition (/, /, $ line, 2); If ($ line = ~ s!  (. +?) & Lt; / messageText & gt; !!) {print "$ date \ n $ 1 \ n"; }}    

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -