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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
12-09-2013, 01:04 PM
|
#1
|
Member
Registered: Feb 2004
Location: e@rth
Distribution: RHEL-3/4/5,Gloria,opensolaris
Posts: 525
Rep:
|
bash script array correlation issue
Hello,
I was just making a bash script to analyze a log file with three important things; acct, date and amount.
So the log file is like for particular date several accts do withdraw/deposit money. I parsed the file line by line and put all these values in array, thought it would be easier to manipulate later like this:
ACCT[]=holds all the account including duplicates
DATE[]= holds all the dates
AMOUNT[]= holds all the money figures
Now at this point, I have to rethink again as I cant correlate 3 of them as I don't know which acct withdraw/deposit money on which date or like if try to find out one particular acct withdraws on which dates/how much as there are no correlation now at this point.
Any ideas how to redesign this?
Thanks in advance.
|
|
|
12-09-2013, 01:46 PM
|
#2
|
Moderator
Registered: May 2001
Posts: 29,415
|
Could be me but I'd use a simple, small database (SQLite3 should do) with epoch, account name, action, amount...
|
|
|
12-09-2013, 02:34 PM
|
#3
|
LQ Guru
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 27,401
|
Quote:
Originally Posted by tanveer
Hello,
I was just making a bash script to analyze a log file with three important things; acct, date and amount. So the log file is like for particular date several accts do withdraw/deposit money. I parsed the file line by line and put all these values in array, thought it would be easier to manipulate later like this:
ACCT[]=holds all the account including duplicates
DATE[]= holds all the dates
AMOUNT[]= holds all the money figures
Now at this point, I have to rethink again as I cant correlate 3 of them as I don't know which acct withdraw/deposit money on which date or like if try to find out one particular acct withdraws on which dates/how much as there are no correlation now at this point.
Any ideas how to redesign this?
|
We can't tell you how to redesign it, until you show us what you have ALREADY designed. Also, you don't show us any samples of the input data, or what your goals are, so we can only guess.
A SQL database as suggested by unSpawn would be by FAR the best way to go, and writing a simple bash script to parse your existing log file and insert those records into a database would be trivial. If you just WANT a bash script, I'd suggest sorting the log file based on account number, which would give you a starting point. From there, read the array until that element changes, and perform some action.
|
|
|
12-15-2013, 12:10 PM
|
#4
|
Member
Registered: Feb 2004
Location: e@rth
Distribution: RHEL-3/4/5,Gloria,opensolaris
Posts: 525
Original Poster
Rep:
|
thanks for the reply and ideas.
I switched from bash to python, the thing I am after bash will be overkill.
Thanks.
|
|
|
All times are GMT -5. The time now is 08:37 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|