programmercarlito has asked for the wisdom of the Perl Monks concerning the following question:

If I wanted to extract errors from a file how would I do it? I know the basics but not sure on this one because some error messages go more than one line. I was storing each line in array but I cant get the complete line. I saw there is a space before the into in each line. I dont know if that will help me create an expression. Thanks

I00020036: Loaded C:\Documents and Settings\ja03\Desktop\DSMProduct\projects\AIS\esounixagent\ServiceInstall\ServiceInstall\IsConfig.ini into \DSM R11\projects\AIS\esounixagent\ServiceInstall\ServiceInstall\IsConfig.ini .

I00020036: Loaded C:\Documents and Settings\ja03\Desktop\DSMProduct\projects\AIS\esounixagent\ServiceInstall\ServiceInstall\Setup.rul into \DSM R11\projects\AIS\esounixagent\ServiceInstall\ServiceInstall\Setup.rul .

E03020039: Unable to load C:\Documents and Settings\ja03\Desktop\DSMProduct\projects\AIS\esounixagent\ServiceInstall\ServiceInstall\String1033.txt into \DSM R11\projects\AIS\esounixagent\ServiceInstall\ServiceInstall\String1033.txt . Text file contains invalid characters .

I00020036: Loaded C:\Documents and Settings\ja03\Desktop\DSMProduct\projects\AIS\esounixagent\ServiceInstall\ServiceInstall\_ISUser1033.dll into \DSM R11\projects\AIS\esounixagent\ServiceInstall\ServiceInstall\_ISUser1033.dll .

I00020036: Loaded C:\Documents and Settings\ja03\Desktop\DSMProduct\projects\AIS\esounixagent\ServiceInstall\ServiceInstall\_ISUser1033.rc into \DSM R11\projects\AIS\esounixagent\ServiceInstall\ServiceInstall\_ISUser1033.rc .

I00020036: Loaded C:\Documents and Settings\ja03\Desktop\DSMProduct\projects\AIS\esounixagent\ServiceInstall\ServiceInstall.ism into \DSM R11\projects\AIS\esounixagent\ServiceInstall\ServiceInstall.ism .

I00020036: Loaded C:\Documents and Settings\ja03\Desktop\DSMProduct\projects\AIS\esounixagent\ServiceInstall\ServiceInstall.sln into \DSM R11\projects\AIS\esounixagent\ServiceInstall\ServiceInstall.sln .

Replies are listed 'Best First'.
Re: Using Expressions
by NetWallah (Canon) on May 03, 2015 at 00:45 UTC
    The trick is to use 2 newlines as a separator. Assuming Error lines start with "E", this one liner would do the trick:
    perl -nE 'BEGIN{$/="\n\n"}; next unless m/^E/; print "$_"' your-file-h +ere.txt

            "You're only given one little spark of madness. You mustn't lose it."         - Robin Williams

      The trick is to use 2 newlines as a separator.

      That's called paragraph mode, and there's a command line switch for that:

      perl -n00 -E 'print if m/^E/' your-file-here.txt
      perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
Re: Using Expressions
by GotToBTru (Prior) on May 03, 2015 at 04:33 UTC

    Did you mean to ask about Regular Expressions? There are tutorials on this site to help with that.

    It would help a lot to know what, precisely, you are looking for as output with your example.

    Dum Spiro Spero
Re: Using Expressions
by Laurent_R (Canon) on May 03, 2015 at 08:52 UTC
    Are you really sure your messages span over more than one line. Looking at your data, it seems to me that they are each on one single line, but just displayed at the screen on two lines because they are two long to fit on one line. The reason I am thinking that is that it does not seem to make sense to put a new line sometimes after "into", sometimes after "into \DSM", sometimes after "into \DSM R11\project".

    Actually, I tried to copy and paste your data into a text editor, and there is no newline character in the middle of the lines. Inserting them here between <code> tags shows a different newline pattern:

    I00020036: Loaded C:\Documents and Settings\ja03\Desktop\DSMProduct\p +rojects\AIS\esounixagent\ServiceInstall\ServiceInstall\IsConfig.ini i +nto \DSM R11\projects\AIS\esounixagent\ServiceInstall\ServiceInstall\ +IsConfig.ini . I00020036: Loaded C:\Documents and Settings\ja03\Desktop\DSMProduct\pr +ojects\AIS\esounixagent\ServiceInstall\ServiceInstall\Setup.rul into +\DSM R11\projects\AIS\esounixagent\ServiceInstall\ServiceInstall\Setu +p.rul . E03020039: Unable to load C:\Documents and Settings\ja03\Desktop\DSMPr +oduct\projects\AIS\esounixagent\ServiceInstall\ServiceInstall\String1 +033.txt into \DSM R11\projects\AIS\esounixagent\ServiceInstall\Servic +eInstall\String1033.txt . Text file contains invalid characters . I00020036: Loaded C:\Documents and Settings\ja03\Desktop\DSMProduct\pr +ojects\AIS\esounixagent\ServiceInstall\ServiceInstall\_ISUser1033.dll + into \DSM R11\projects\AIS\esounixagent\ServiceInstall\ServiceInstal +l\_ISUser1033.dll . I00020036: Loaded C:\Documents and Settings\ja03\Desktop\DSMProduct\pr +ojects\AIS\esounixagent\ServiceInstall\ServiceInstall\_ISUser1033.rc +into \DSM R11\projects\AIS\esounixagent\ServiceInstall\ServiceInstall +\_ISUser1033.rc . I00020036: Loaded C:\Documents and Settings\ja03\Desktop\DSMProduct\pr +ojects\AIS\esounixagent\ServiceInstall\ServiceInstall.ism into \DSM R +11\projects\AIS\esounixagent\ServiceInstall\ServiceInstall.ism . I00020036: Loaded C:\Documents and Settings\ja03\Desktop\DSMProduct\pr +ojects\AIS\esounixagent\ServiceInstall\ServiceInstall.sln into \DSM R +11\projects\AIS\esounixagent\ServiceInstall\ServiceInstall.sln .

    In brief, there does not seem to be new lines within your error messages. It seems to be merely a screen display artifact.

    Je suis Charlie.