LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-09-2011, 10:17 PM   #1
pghosh06
LQ Newbie
 
Registered: Feb 2011
Posts: 5

Rep: Reputation: 0
unix shell script to generate a bar graph


Hello,I am a complete newbie in shell scripting.
I am working on a small project where I have tons of data to analyze.
I was wondering if it would be possible to write a script to generate a bar graph/chart/histogram etc that can make the analysis part simpler.

While dealing with so much data, i fear a manual approach could lead to human errors and hence thought that a script might be a better approach.

Please help.
 
Old 02-09-2011, 10:36 PM   #2
MS3FGX
LQ Guru
 
Registered: Jan 2004
Location: NJ, USA
Distribution: Slackware, Debian
Posts: 5,852

Rep: Reputation: 361Reputation: 361Reputation: 361Reputation: 361
What exactly are you looking to do? Create a bar graph right in the terminal as the script runs, or create an image file that contains bar graphs representing the data?
 
Old 02-09-2011, 10:42 PM   #3
pghosh06
LQ Newbie
 
Registered: Feb 2011
Posts: 5

Original Poster
Rep: Reputation: 0
I think creating an image file that contains bar graphs representing the data would really help.
 
Old 02-09-2011, 11:12 PM   #4
A.Thyssen
Member
 
Registered: May 2006
Location: Brisbane, Australia
Distribution: linux
Posts: 158

Rep: Reputation: 44
First have a look at the simple script...
http://www.ict.griffith.edu.au/~anth...are/percent.sh

Another snippet that may be of interest...

Progress Bar

This is a all bash method (except for the sleep)

Code:
  bar="=================================================="
  barlength=${#bar}
  i=0
  while ((i < 100)); do
    n=$((i*barlength / 100))       # Number of bar segments to draw $((i/2))
    printf "\r[%-${barlength}s]" "${bar:0:n}"
    ((i += RANDOM%5+2))            # i = percentage done
    sleep 1
  done
  echo
Of course 'i' should be set from somewhere meaningful.
 
Old 02-10-2011, 03:01 AM   #5
b0uncer
LQ Guru
 
Registered: Aug 2003
Distribution: CentOS, OS X
Posts: 5,131

Rep: Reputation: Disabled
You can easily write a script to run R or Gnuplot, which can produce several kinds of graphs, including bar graphs, with various options. Personally I prefer Gnuplot over R for plotting, but the choice is yours (and presumably there are other alternatives as well). Either app is able to "work on" a file which contains the directives to do something (e.g. to do a bar graph, in this case), and that file you can create on the fly with a suitable script, which enables you to work on large amounts of data, if it's organized.

See the homepages of R and Gnuplot for more information, to begin with. First use them interactively (i.e. start either one, and then start doing things) to get to grips with them. Creating a bar chart is fairly easy, if your data is in a file organized so that the program is able to read it. When you know the (few) necessary things to work out the graph, put them into a file and have the program "run" that file. Once that works, write a small shell script, for example, that dynamically creates the file(s) (if you need more than one), and you have a solution.

Another approach: for example if you had N data files that had different names (but same structure) and you wanted N graphs out of them, you could create just one file for, say, Gnuplot that produced a bar graph from a given file. Then you didn't need to create several Gnuplot scripts/directive files, but one that worked on a certain data file, and in a (for example bash) script just link each real data file in turn to the name you used in the Gnuplot script. That's what I'd do, and just tell Gnuplot to take the necessary names etc. from the file (column names for example). Examples on how to create a bar graph are plenty (at least for R and Gnuplot), so you should be able to build one that you need quickly.

Edit: the programs can output a variety of formats, so you'll surely find something that you like. In addition they don't need graphical user interface for this, so you can run this easily in a shell, and then just get the results and look at them. If the data files are very large, this can take some time (depending on how you do the graph, but a file with millions of lines may take a moment to get through), but if done right, you don't need to supervise it when it's done.

Last edited by b0uncer; 02-10-2011 at 03:09 AM.
 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Generate Items for a case shell script Snake_Eyes_ Linux - General 8 12-12-2009 06:56 AM
Generate Graph from iperf Statistics tassadaque Linux - Networking 1 08-20-2008 12:04 PM
Generate a random number from a bourne shell script lothario Linux - Software 2 03-01-2007 11:01 PM
Shell Script Progress bar rooch84 Linux - Software 8 09-03-2005 04:55 PM
PROGRESS BAR with shell script murugesan Linux - Software 5 12-13-2004 09:03 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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

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