The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 08-26-2007
baghera baghera is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 23
List to columns and awk help

Hi I'm new to this forum and I'm a beginner when it comes to shell programming and awk programming. But I have the following problem:

I've a list like this:

1
2
3
4
5
6
7
8

Either from a file or output from a command. What I would like to do is to arrange these values into x columns with values in each column like this:

1 2 3 4
5 6 7 8

Where x specifies how many columns I would like. Then I would like to add all the values from column 1 and divide it with the numbers of rows (in this case 2).

forgot something: this is for a bourne shell script. Is it possible to have x as a variable input when running the script?

Or is it possible to, instead of making columns, to add every x element in the list and then take an average?

Last edited by baghera; 08-26-2007 at 01:09 PM..