List to columns and awk help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting List to columns and awk help
# 15  
Old 08-28-2007
is this a new requirement? if yes, then start a new thread.

You can do that by this command in the end section

Code:
print NR

# 16  
Old 08-28-2007
No it is still the same problem, but I'm much closer to a solution.

So I'm sorry if it confusing some of you. While looking for a way to solve my problem I've been looking at sed/awk/perl and simple bash-scripts. Since it did not matter in which language the script was written I looked at all of them.

But I found this with the help you gave me:

Code:
xargs -n 2 | awk ' {sum1+=$1} {sum2+=$2} {sum3+=$3} {sum4+=$4} END {print sum1/NR sum2/NR sum3/NR sum4/NR}'

I don't think it can be more simple. Or can it? First I use xargs to split my list into columns and then I use awk to count and divide the so that I get the average value from each column. What remains is to format the outprint in a nice way.

Last edited by baghera; 08-28-2007 at 09:18 AM..
# 17  
Old 08-28-2007
Code:
xargs -n 2 | awk ' {sum1+=$1} {sum2+=$2} {sum3+=$3} {sum4+=$4} END {print sum1/NR, sum2/NR, sum3/NR, sum4/NR}'

# 18  
Old 08-28-2007
Quote:
Originally Posted by vgersh99
Code:
xargs -n 2 | awk ' {sum1+=$1} {sum2+=$2} {sum3+=$3} {sum4+=$4} END {print sum1/NR, sum2/NR, sum3/NR, sum4/NR}'

Thanks, I found several ways to make the outprint more beautiful. I just want to say to everybody that helped me: THANK YOU.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to use "awk" to print columns from different files in separate columns?

Hi, I'm trying to copy and paste the sixth column from a bunch of files into a single file having each column pasted in separate columns (and not one after each other in just one column.) I tried this code but works only partially because it copied and pasted 50 rows of each column... (6 Replies)
Discussion started by: Frastra
6 Replies

2. Shell Programming and Scripting

Portable way to print list in columns

so if i have a list of file names, on linux system, we can use the column command to split them up into columns. sadly, the "columns" command does not exist on some OSes. so i found that the pr command can also work. but, pr tends to truncate the names. There's a way around that on... (3 Replies)
Discussion started by: SkySmart
3 Replies

3. UNIX for Dummies Questions & Answers

How convert space separated list to matched columns?

Hi I have been racking my (limited) brains to get this to work without success I have a file output which is a list of lists - ie a single column of data that is separated by space into sub lists below - I need to both split this so that each list is in a separate column (eg tab or semicolon... (8 Replies)
Discussion started by: Manchesterpaul
8 Replies

4. UNIX for Dummies Questions & Answers

Pick out columns according to list of column names

Hi Everyone: I'm new to linux and I was wondering what the best way to approach the following problem was. I have 2 files: File A: ID123 ID234 ID456 File B: ID123 ID234 ID345 ID456 A B C D E F G H I J K L Based on the list of IDs in File A, I want to output only the... (3 Replies)
Discussion started by: chongm88
3 Replies

5. Shell Programming and Scripting

break from a single list into multiple columns

Hi Guys, I am prety new to the hell scripting world. I am running some grep/cut commands and extracting from a csv file into a list. But the final product I need is that the whole list that I now have has to be broken and separated into columns. Say what I now have extracted is a list of... (6 Replies)
Discussion started by: h_rishi
6 Replies

6. Shell Programming and Scripting

Converting a list to X columns of csv (& wrapping a command around it)

Hi All, Random question, how would you convert a data file from a list like so: 12345 12346 12347 12348 12349 12350 ... <snip 100+ lines> ... to comma separated X columns across: 12345,12346,12347 12348,12349,12350 Why would you want to do this? The background to this is a... (2 Replies)
Discussion started by: craigp84
2 Replies

7. UNIX for Dummies Questions & Answers

Creating columns from a list

I have a list below, how can I have things separated nicely in columns mv browseDir.tcsh browseDir.csh mv checkSRDist.tcsh checkSRDist.csh mv create-data-tinv.tcsh create-data-tinv.csh mv createDocs.tcsh createDocs.csh mv createMisfit.tcsh createMisfit.csh mv createModel.tcsh... (4 Replies)
Discussion started by: kristinu
4 Replies

8. Shell Programming and Scripting

Deleting columns by list or file

Dear specialists out there, please help a poor awk newbie: I have a very huge file to process consisting of 300000 columns and 1500 rows. About 20000 columns shall be deleted from that file. So it is clear, that I can't do this by writing down all the columns in an awk command like $1, $x etc.... (5 Replies)
Discussion started by: flxms
5 Replies

9. Shell Programming and Scripting

how to AWK columns from $1 to $5 without $2 $3 $4

hello cant find a way to make something like: awk '{print $1 - $5}' somefile which is printing $1 $2 $3 $4 $5 should make an array or something? i just dont wanna write $1 $2 $3 $4 $5 to awk input i need to use from $1 to $5 and print them all and then i need to swith to: from $6 to $10 (3 Replies)
Discussion started by: tip78
3 Replies

10. Shell Programming and Scripting

list of unmatched columns

Hi , I have two files want to compare and list of column values and postion which are not matched between two files,I can use diff but it will return rows from two files which are matched and unmatched columns.I wrote the below script but not working. f1=$1 f2=$2 for i in 1 do file1=`cat... (3 Replies)
Discussion started by: mohan705
3 Replies
Login or Register to Ask a Question