Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

REQ: Help with parsing please 2

Status
Not open for further replies.

Kipnep70

Technical User
Nov 18, 2003
81
US
This is what I got so far ..

Code:
BEGIN{
        error_no=0
        while(1)

        }
                        /status error_no / {
                        error_no++
                        if(error_no==200)
                        {
                                print "End Searching " 
                                break
                        }
                        print $8
        }
}

I also am trying to work from a one-liner ...

Code:
 cat error.txt | grep status | awk '/status 1 /{a=$8;print a>"status1.txt"}'

What I am ultimately trying to do is search through a log file and sort out all the lines with a "status" string followed by a number 1 - 200. For example I want the string "status 1" to be dumped to status1.txt .. all the "status 2" strings I want dumped to a status2.txt and so forth.

anyway I'm trying to figure out how to combine the codes above to get what I want.. I know that I'm missing some stuff, but at this point I'm totally lost.

Thanks,

 
Are the status and the number strings in the same columns at all times? Is the data in order? If yes, e.g. $2 & $3, then this is super easy.
Code:
awk '/status [12]/print $8 > $2 $3".txt";{if(/status 200/)exit}' error.txt

Cheers,
ND [smile]
 
ND,

Thanks for your help.

As an example here are two lines from the error.txt that I need sorted ..

04:03:06.888 [21205] <16> log_in_errorDB: backup of client ABCclient exited with status 1 (the requested operation was partially successful)
05:02:31.193 [21205] <16> log_in_errorDB: backup of client XYZclient exited with status 41 (network connection timed out)

The result I want is that in the first line (status 1) the client name in field 8 ($8), ABCclient, will be dumped to a status1.txt text file and in the 2nd line, XYZclient dumped to a status41.txt file.

I tried running the command you told me:

Code:
awk '/status [12]/print $8 > $11 $12".txt";{if(/status 200/)exit}' error.txt

But I received the following error:

Code:
# awk '/status [12]/print $8 > $11 $12".txt";{if(/status 200/)exit}' error.txt
 syntax error The source line is 1.
 The error context is
                /status >>>  [12]/print <<<  $8 > $11 $12".txt";{if(/status 200/)exit}
 awk: Quitting
 The source line is 1.

Any advice?

I ran the following ... which produced the above error:
 
A starting point:
awk '$11=="status"{print $8>"status"$12".txt"}' error.txt

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Oh, if you still need to filter the status number from to 1-200 then ammend the filter portion

awk '$11=="status" && $12>=1 && $12<=200 {...

Cheers,
ND [smile]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top