Sponsored Content
Full Discussion: 2 input files for awk
Top Forums Shell Programming and Scripting 2 input files for awk Post 302129299 by koti_rama on Monday 30th of July 2007 10:24:50 AM
Old 07-30-2007
2 input files for awk

Hi,
i have 2 files like f1 and f2
f1:
1
Note: some times it will be cahnged to 2 and 3.

f2:
1:20
2:30
4:50
6:70
8:90
3:20
1:30
1:40

output:
1:80
(sum of 1)


for this i wrote awk script.but it's not working.

cat f1.txt | awk '
BEGIN {
FS=":"
load_type=$1;
}

{
number[$1]++;
totaltime[$1]=totaltime[$1]+$2;
}
END {

f ( load_type==1 )
workload="Light_load_avgfile";
else if (load_type==2)
workload="Medium_load_avgfile";
else
workload="Heavy_load_avgfile";


for( code in totaltime )
{
#calculating avg;
avg=totaltime[code]/number[code];

print code"|"avg "|">workload

}


}' f2.txt

please help me on this
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk reading 2 input files but not getting expected value

I'm reading 2 input files but not getting expected value. I should get an alpha value on file_1_data but not getting any. Please help. >cat test6.sh awk ' FILENAME==ARGV { file_1_data=$0; print "----- 1 Line " NR " -----" $1; next } FILENAME==ARGV { file_2_data=$0; print "----- 2... (1 Reply)
Discussion started by: pdtak
1 Replies

2. Shell Programming and Scripting

Splitting input files into multiple files through AWK command

Hi, I needs to split *.txt files from single directory depends on the some mutltiple input values. i have wrote the code like below for file in *.txt do grep -i -h "value1|value2" $file > $file; done. My requirment is more input values needs to be given in grep; let us say 50... (3 Replies)
Discussion started by: arund_01
3 Replies

3. Shell Programming and Scripting

awk read input files

hi, i'm a beginner in writing awk scripts and I have a problem with reading input files. Requirement for my programm: compare file1 to file2 and check if value in column1 is equal and value in column5 is different. File 1: 180 P 01.01.2008 30.06.2008 2 180 P 01.07.2008 ... (10 Replies)
Discussion started by: tgooper
10 Replies

4. Shell Programming and Scripting

Comparing 2 input files -Awk

Compare 2 files and print the values input1 (c1 20 100 X_y10) along with one closest highest (c1 100 200 X_y10) and one lowest values (c1 10 15 X_y10) from input2 input1 c1 20 100 X_y10 input2 c1 5 10 X_y10 c1 10 15 X_y10 c1 100 200 X_y10 c1 200 300 X_y10 output ... (8 Replies)
Discussion started by: bumblebee_2010
8 Replies

5. Shell Programming and Scripting

AWK using two input files

Hi , i have two input files one is input.gz and another is ( input.txt) text file.in gz format input file each record contains 10 fields and corresponding header value is present in the text file as a single record i.e text file contains only 10 records which is header value,so output of the awk... (1 Reply)
Discussion started by: Ajoy
1 Replies

6. Shell Programming and Scripting

Help with reading two input files in awk

Hello, I'm trying to write an awk program that reads two files inputs. example, file 1: 0.00017835 0.000176738 0.00018811 0.000189504 0.000188155 0.000180065 0.000178991 0.000178252 0.000182513 file 2: 1.7871769E-05 1.5139576E-16 1.5140196E-16 1.5139874E-16 1.7827407E-04 ... (5 Replies)
Discussion started by: joseamck
5 Replies

7. UNIX Desktop Questions & Answers

awk using 2 input files instead of while loops

Hi Friends, I have two files as input with data that looks like this: file1.txt 1 2 3 4 file2.txt a,aa b,bb c,cc d,dd e,ee f,ff instead of me doing 2 while loops to get the combinations while read line_file1 (2 Replies)
Discussion started by: kokoro
2 Replies

8. Shell Programming and Scripting

FOR loop with multiple files as input and awk

Hi all , i want to pass multiple files as input to a for loop for i in file1 file2 file3 do some awk action < $i >> $i.out done but im getting error in that for loop is the way i use to pass files to awk using for correct and 2.we can directly pass multiple files to awk as... (7 Replies)
Discussion started by: zozoo
7 Replies

9. Shell Programming and Scripting

Awk: Replacement using 2 diff files input and comparison

Requirement: If $5(date field) in ipfile is less than $7(date field) in deact file & $1 of ipfile is present in deactfile then $1 to be replaced by $2,$3,$4,$5,$6 of deact file else if $5(date field) in ipfile is greater than $7(date field) in actfile & $1 of ipfile is present in actfile then... (5 Replies)
Discussion started by: siramitsharma
5 Replies

10. Shell Programming and Scripting

Parse input of two files to be the same in awk

I have two files that I am going to use diff to find the differences but need to parse them before I do that. I have include the format of each file1 and file2 with the desired output of each (the first 5 fields in each file). The first file has a "chr" before the # that needs to be removed. I... (1 Reply)
Discussion started by: cmccabe
1 Replies
GEARMAN_CLIENT_ADD_TASK(3)					     Gearmand						GEARMAN_CLIENT_ADD_TASK(3)

NAME
gearman_client_add_task - Gearmand Documentation, http://gearman.info/ SYNOPSIS
#include <libgearman/gearman.h> gearman_task_st *gearman_client_add_task(gearman_client_st *client, gearman_task_st *task, void *context, const char *function_name, const char *unique, const void *workload, size_t workload_size, gearman_return_t *ret_ptr) gearman_task_st *gearman_client_add_task_high(gearman_client_st *client, gearman_task_st *task, void *context, const char *function_name, const char *unique, const void *workload, size_t workload_size, gearman_return_t *ret_ptr) gearman_task_st *gearman_client_add_task_low(gearman_client_st *client, gearman_task_st *task, void *context, const char *function_name, const char *unique, const void *workload, size_t workload_size, gearman_return_t *ret_ptr) Link with -lgearman DESCRIPTION
gearman_client_add_task() creates a task and adds it to the given gearman_client_st. Execution of the task does now begin until gear- man_client_run_tasks() is called. If the unique value is not set, then a unique will be assigned. gearman_client_add_task_high() and gearman_client_add_task_low() are identical to gearman_client_do(), only they set the priority to either high or low. RETURN VALUE
The gearman_task_st is created and a pointer to it is returned. On error NULL is returned and ret_ptr is set with a gearman_return_t. HOME
To find out more information please check: http://gearman.info/ See also gearmand(8) libgearman(3) AUTHOR
Data Differential http://www.datadifferential.com/ COPYRIGHT
2012, Data Differential, http://www.datadifferential.com/ 0.33 May 04, 2012 GEARMAN_CLIENT_ADD_TASK(3)
All times are GMT -4. The time now is 03:58 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy