Sponsored Content
Full Discussion: Shorter AWK for my code?
Top Forums UNIX for Dummies Questions & Answers Shorter AWK for my code? Post 302461678 by calitiggr on Tuesday 12th of October 2010 03:23:58 AM
Old 10-12-2010
Shorter AWK for my code?

Hi Folks,

I know my code works, but I'm still a newbie at arrays and how they function.

Is there is shorter way to write my code? I'm taking averages in multiple files and concatenating output into 1 file.

TIA!

Code:
for file in *; 
do 
awk -F"\t" '{a1+=$1}{a2+=$2}{a3+=$3} {a4+=$4}{a5+=$5} {a6+=$6} {a7+=$7} {a8+=$8}  {a9+=$9} {a10+=$10} {a11+=$11} {a12+=$12} {a13+=$13} {a14+=$14} {a15+=$15} {a16+=$16}  END 
	{print FILENAME, "\t"a1/(NR), "\t"a2/(NR), "\t"a3/NR, "\t"a4/NR, "\t"a5/NR, "\t"a6/NR, "\t"a7/NR, "\t"a8/NR, "\t"a9/NR, "\t"a10/NR,"\t"a11/NR,"\t"a12/NR,"\t"a13/NR,"\t"a14/NR, "\t"a15/NR,"\t"a16/NR}' 
	$file >> /Users/calitiggr/Desktop/S/S-$i
done

 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Deleting shorter lines from data file

Hello, I have the following data file structure: 1234 text 2345 text 3456 text text text 4567 text text text 5678 text text text 6789 text text text I simply want to delete all of the lines that only have one text column (i.e. the first two lines in this case). The output would be:... (1 Reply)
Discussion started by: palex
1 Replies

2. Shell Programming and Scripting

Need help to understand Awk code.

Hi Guys, Can someone please explain this code to me. I could figure out it's adding and comparing two fields but I am not sure which ones. sort -t"|" -k3.1 /tmp/mpcashqc.xtr| awk -F"|" '{CHECKAMT+=$3;BATCHTOT=$4;\ items++}END{for(i in CHECKAMT) if (CHECKAMT!=BATCHTOT)... (6 Replies)
Discussion started by: nua7
6 Replies

3. Shell Programming and Scripting

Help in developing an awk code

#!/bin/ksh set -x FILENAME=$1 #To calculate debit and credit DEBIT=`awk -F, '{value=$28 ;if(value<0) {debit+=value}} END {print debit}' $FILENAME` CREDIT=`awk -F, '{value=$28 ;if(value>0) {credit+=value}} END {print credit}' $FILENAME` #This part is not working since the debit value is... (2 Replies)
Discussion started by: selvankj
2 Replies

4. Shell Programming and Scripting

Need help with AWK code using xargs

Hi, I have a colon-separated file which contains names of users, among other details. My aim is to extract the line with the name and assign the name to a variable. A sample file is as follows -- ID: 123456 DEPARTMENT: xyz NAME: Bar, Foo Considering the Tabs between the colon and the... (6 Replies)
Discussion started by: Subu1987
6 Replies

5. Shell Programming and Scripting

Help with AWK Code

hello, I would appreciate a little assistance with a process I'm trying to automate. I have several files that are zipped in central location, all follow the same naming conventions i.e (file 1, file 2, etc). what i would like to do is unzip the files and combined them into one file, basically... (2 Replies)
Discussion started by: mrn970
2 Replies

6. Shell Programming and Scripting

Combine columns from many files but keep them aligned in columns-shorter left column issue

Hello everyone, I searched the forum looking for answers to this but I could not pinpoint exactly what I need as I keep having trouble. I have many files each having two columns and hundreds of rows. first column is a string (can have many words) and the second column is a number.The files are... (5 Replies)
Discussion started by: isildur1234
5 Replies

7. Shell Programming and Scripting

Optimize awk code

sample data.file: 0,mfrh_green_screen,1454687485,383934,/PROD/G/cicsmrch/sys/unikixmain.log,37M,mfrh_green_screen,28961345,0,382962--383934 0,mfrh_green_screen,1454687785,386190,/PROD/G/cicsmrch/sys/unikixmain.log,37M,mfrh_green_screen,29139568,0,383934--386190... (7 Replies)
Discussion started by: SkySmart
7 Replies

8. Shell Programming and Scripting

Combining awk code into one

the following code works perfectly for me: # AWK 1 gawk -F, '/,'${ThisMonthDOW}' '${ThisMonthMON}' :: '${ThisMonthYEA}',/ { if (NF == 10) ... (6 Replies)
Discussion started by: SkySmart
6 Replies

9. UNIX for Beginners Questions & Answers

Just want to ask if there is a shorter hand to doing this one liner

Hi all, In Oracle, I am using SQL*Plus and selecting all rows in a table and spooling to a file as pipe delimited. I have to use pagesize 0 but unfortunately, using this option excludes the header and I can't get around having it to display the header fields. So to get around this, I have to... (2 Replies)
Discussion started by: newbie_01
2 Replies
UPTIME(1)							Linux User's Manual							 UPTIME(1)

NAME
uptime - Tell how long the system has been running. SYNOPSIS
uptime uptime [-V] DESCRIPTION
uptime gives a one line display of the following information. The current time, how long the system has been running, how many users are currently logged on, and the system load averages for the past 1, 5, and 15 minutes. This is the same information contained in the header line displayed by w(1). System load averages is the average number of processes that are either in a runnable or uninterruptable state. A process in a runnable state is either using the CPU or waiting to use the CPU. A process in uninterruptable state is waiting for some I/O access, eg waiting for disk. The averages are taken over the three time intervals. Load averages are not normalized for the number of CPUs in a system, so a load average of 1 means a single CPU system is loaded all the time while on a 4 CPU system it means it was idle 75% of the time. FILES
/var/run/utmp information about who is currently logged on /proc process information AUTHORS
uptime was written by Larry Greenfield <greenfie@gauss.rutgers.edu> and Michael K. Johnson <johnsonm@sunsite.unc.edu>. Please send bug reports to <albert@users.sf.net> SEE ALSO
ps(1), top(1), utmp(5), w(1) Cohesive Systems 26 Jan 1993 UPTIME(1)
All times are GMT -4. The time now is 05:30 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy