Append awk results into file or array


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Append awk results into file or array
# 1  
Old 09-03-2014
Append awk results into file or array

Code:
for a in {1..100}
do
awk '{ sum+=$a} END {print sum}' a=$a file1 > file2
done

I know I will get only one number if following the code above, how can I get 100 sum numbers in file2?

Last edited by Don Cragun; 09-04-2014 at 06:48 AM.. Reason: Add CODE tags.
# 2  
Old 09-03-2014
Please use [code] and [/code] tags around any posted code.

Is this what you are after:

Code:
for a in {1..100}
do
    awk '{ sum+=$a} END {print sum}' a=$a file1
done > file2

or

Code:
awk '{for(i=1;i<=100;i++) sum[i]+=$i} END {$0=x; for(i=1;i<=100;i++) $i=sum[i]; print }' file1 > file2

This User Gave Thanks to Chubler_XL For This Post:
# 3  
Old 09-03-2014
Thanks~
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Bash to append array value to file before copying

The bash stores each uniqueid in an array and then passes them to %q to get the unique path. That seems to work what I am having trouble with is renaming each .png with the unique value in %q. I thought it was working but upon closer inspection, a .png file is being sent to scp.... but only 1 and... (21 Replies)
Discussion started by: cmccabe
21 Replies

2. UNIX for Beginners Questions & Answers

awk to update file with partial matching line in another file and append text

In the awk below I am trying to cp and paste each matching line in f2 to $3 in f1 if $2 of f1 is in the line in f2 somewhere. There will always be a match (usually more then 1) and my actual data is much larger (several hundreds of lines) in both f1 and f2. When the line in f2 is pasted to $3 in... (4 Replies)
Discussion started by: cmccabe
4 Replies

3. Shell Programming and Scripting

awk file sum results

I ran this script: #!/bin/bash ./disk-usage-JM.pl > jm_out InFile="jm_out" OutFile="jm_temp" awk '{if (!match(" \t",substr($0,1,1))) {server=$0; next} if (substr($0,1,1)==" ") {workspace=$0; next} print server,workspace,$0}' \ $InFile >$OutFile rm jm_out against this... (2 Replies)
Discussion started by: master-of-puppe
2 Replies

4. Shell Programming and Scripting

Awk: Append new elements to an array

Hi all, I'm dealing with a bash script to merge the elements of a set of files and counting how many times each element is present. The last field is the file name. Sample files: head -5 *.tab==> 3J373_P15Ac1y2_01_LS.tab <== chr1 1956362 1956362 G A hom ... (7 Replies)
Discussion started by: lsantome
7 Replies

5. Shell Programming and Scripting

awk to append data to a file

Hi I search for certain values in a file across many directories using the following awk code awk '/Sl.*thickness/ {Sl=$3;Tt=$NF}END{print Sl, Tt}' DILAT.DAT What I would like to do is write out Sl and Tt obtained from these files from many directories to a single file. So for example if... (2 Replies)
Discussion started by: lost.identity
2 Replies

6. Shell Programming and Scripting

Create a file from ls -l command and append additional info to results

I need to be able to take the results from ls -l command and modify the output as follows: I will run ls -l *.mak My results will be aa.mak bb.mak cc.mak I then need to take those results and create a file that has the following info: dsjj/ubin/aa dsjj/ubin/bb dsjj/ubin/cc ... (3 Replies)
Discussion started by: jclanc8
3 Replies

7. Shell Programming and Scripting

Adding results of a find to an array

I'm trying to add the paths of all the xml files in certain directories to an array. I want to use the array later in my code. Anyway, for some reason this isn't working. Any help would be appreciated. Path_Counter=0 for result in "find * -name '*.xml'"; do XmlPath="$result" echo... (2 Replies)
Discussion started by: Fly_Moe
2 Replies

8. Shell Programming and Scripting

Compare Array results

Hi, In a kshell , i need to compare the results of two array . each Non-match value should copy to a new array. For example: ========== Array one contain the following values: A B C Array two contain the following values: C F A E After comparing this arrays , a new array should... (4 Replies)
Discussion started by: yoavbe
4 Replies

9. Shell Programming and Scripting

Results of command execution into array

Hi Can anybody tell me how can I dump the results of execution of a command into array form? For example, I want to execute: and put each part of the result in an array element: Thanks (2 Replies)
Discussion started by: alirezan
2 Replies

10. Shell Programming and Scripting

how to append into array thru awk

hey champs, i have variable as field_dtls, which has values like CLIENT ID|FAMILY NAME|MIDDLE NAME|FIRST NAME|COUNTRY NAME|ADDRESS|NATIONAL ID|PASSPORT NUMBER so, echo "$field_dtls" CLIENT ID|FAMILY NAME|MIDDLE NAME|FIRST NAME|COUNTRY NAME|ADDRESS|NATIONAL ID|PASSPORT NUMBER but i... (2 Replies)
Discussion started by: manas_ranjan
2 Replies
Login or Register to Ask a Question