LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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
  Search this Thread
Old 12-09-2013, 12:04 PM   #1
tanveer
Member
 
Registered: Feb 2004
Location: e@rth
Distribution: RHEL-3/4/5,Gloria,opensolaris
Posts: 525

Rep: Reputation: 39
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.
 
Old 12-09-2013, 12:46 PM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Could be me but I'd use a simple, small database (SQLite3 should do) with epoch, account name, action, amount...
 
Old 12-09-2013, 01:34 PM   #3
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,636

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by tanveer View Post
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.
 
Old 12-15-2013, 11:10 AM   #4
tanveer
Member
 
Registered: Feb 2004
Location: e@rth
Distribution: RHEL-3/4/5,Gloria,opensolaris
Posts: 525

Original Poster
Rep: Reputation: 39
thanks for the reply and ideas.
I switched from bash to python, the thing I am after bash will be overkill.

Thanks.
 
  


Reply



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
BASH-Adding array element: Naming issue using array[${#array[*]}]=5 calvarado777 Programming 8 07-26-2013 09:48 PM
bash shell script split array robertngo Programming 13 06-19-2011 11:01 PM
Need clarification for file to bash script array. lifeforce4 Programming 3 11-27-2009 10:09 AM
Bash Script Array index value Kedelfor Programming 10 04-29-2009 04:37 AM
MAJOR problem ... bash script array HELP !!!!! michael_util Slackware 1 02-13-2004 06:51 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 10:13 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration