LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Help w/ script to read file and parse log message (https://www.linuxquestions.org/questions/linux-general-1/help-w-script-to-read-file-and-parse-log-message-800205/)

shyork2001 04-05-2010 04:48 PM

Help w/ script to read file and parse log message
 
Hi,

I am working on the script to parsing the specific message like "aaaa" in multiple log files like N1-***,N2-***,N3-***...
The script is to find the list of lof files which contains the message "aaaa" and export the list into excel filE.

Can anyone give help?

Thanks

hi2arun 04-05-2010 06:57 PM

Hello,

If the pattern "aaaa" is more specific, then a simple grep should do.

Quote:

grep "aaaa" /path/of/files/*
Say, to automate.. like finding the files and create an excel sheet, perl should be easy to do.

shyork2001 04-05-2010 08:05 PM

thanks.

I am not very famiar to perl.

Can bash shell can accomplish this?

TB0ne 04-06-2010 09:59 AM

Quote:

Originally Posted by shyork2001 (Post 3925548)
thanks.

I am not very famiar to perl.

Can bash shell can accomplish this?

Yes, it can find it, but not automatically write an Excel file. It can write a comma-separated values (CSV) file, suitable for easy import/opening by Excel. Perl has modules that will allow you to create an Excel file on the fly, though.

So, do it in bash and save as CSV, or learn Perl. Either way, YOU need to do the work. We are not going to write the code for you. Post what you've written, and where you're getting stuck, and we can "give help". Otherwise, there are many scripting tutorials you can find on Google.

mweed 04-06-2010 11:48 AM

Try using awk. it will do a bit more than just grep.

example:
Code:

awk -F'[ .]' '/aaaa/ { print $6 "," $1 "," $2 }'
-F specified the field separator. it can either be a single character -F: for example to split fields by a colon. Or a regular expression as above. The second part '/aaaa/ { print $6 "," $1 "," $2 }' is the actual awk code. Very basic for what awk can do. the /aaaa/ is the search expression. This is full extended regular expression capable. the print statement is the output $6 etc specifies which field to print. the data in the quotes is passed right through. The above will output in CSV format which can be loaded in excel.

Example:
Code:

$>cat << EOINPUT | awk -F'[ .]' '/aaaa/ { print $6 "," $1 "," $2 }'
> This is.a test aaaaaa of stuff
> this line will not print
> blahhh aaaaa.a.a.a.a.a.a.a.a.a yayyy
> EOINPUT
of,This,is
a,blahhh,aaaaa



All times are GMT -5. The time now is 03:39 PM.