LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
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.

Notices

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

Rep: Reputation: 0
Smile 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
 
Old 04-05-2010, 06:57 PM   #2
hi2arun
Member
 
Registered: Apr 2010
Distribution: Fedora
Posts: 109
Blog Entries: 4

Rep: Reputation: 33
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.
 
Old 04-05-2010, 08:05 PM   #3
shyork2001
LQ Newbie
 
Registered: Apr 2010
Posts: 4

Original Poster
Rep: Reputation: 0
thanks.

I am not very famiar to perl.

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

Rep: Reputation: 2359Reputation: 2359Reputation: 2359Reputation: 2359Reputation: 2359Reputation: 2359Reputation: 2359Reputation: 2359Reputation: 2359Reputation: 2359Reputation: 2359
Quote:
Originally Posted by shyork2001 View Post
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.

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

Rep: Reputation: 17
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
 
  


Reply


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
Trackbacks are Off
Pingbacks are On
Refbacks are 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


All times are GMT -5. The time now is 01:48 AM.

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