Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 04-05-2010, 04:48 PM   #1
LQ Newbie
Registered: Apr 2010
Posts: 4

Rep: Reputation: 0
Smile Help w/ script to read file and parse log message


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?

Old 04-05-2010, 06:57 PM   #2
Registered: Apr 2010
Distribution: Fedora
Posts: 109
Blog Entries: 4

Rep: Reputation: 34

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

grep "aaaa" /path/of/files/*
Say, to automate.. like finding the files and create an excel sheet, perl should be easy to do.
Old 04-05-2010, 08:05 PM   #3
LQ Newbie
Registered: Apr 2010
Posts: 4

Original Poster
Rep: Reputation: 0

I am not very famiar to perl.

Can bash shell can accomplish this?
Old 04-06-2010, 09:59 AM   #4
LQ Guru
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 19,077

Rep: Reputation: 4378Reputation: 4378Reputation: 4378Reputation: 4378Reputation: 4378Reputation: 4378Reputation: 4378Reputation: 4378Reputation: 4378Reputation: 4378Reputation: 4378
Originally Posted by shyork2001 View Post

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.

Last edited by TB0ne; 04-06-2010 at 10:00 AM.
Old 04-06-2010, 11:48 AM   #5
Registered: Mar 2006
Posts: 33

Rep: Reputation: 17
Try using awk. it will do a bit more than just grep.

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.

 $>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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
receive and parse email in bash (or execute script when message is received) Guyverix Linux - Newbie 2 11-15-2009 07:29 AM
Script to read a log file?? helptonewbie Programming 11 11-17-2007 08:18 PM
Parse lines need from /var/log/message but excluding... grant-skywalker Linux - General 8 03-20-2007 02:30 PM
Help w/ script to read file and parse variables cslink23 Linux - General 18 11-26-2006 02:22 AM
How to read ans parse MS word file using a Linux Shell script. Alek Linux - General 2 11-10-2003 02:07 PM > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 07:26 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration