awk program for 3 files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk program for 3 files
# 1  
Old 07-27-2015
Tools awk program for 3 files

I have 3 files, as below:

*File1:*

Code:
    5372,5372,0,0,,1,0,1,1,0,1,0,0,0,0,0,0,1107,1107,,1.620000,1,2015-08-12,,,,,,,,,,,,,,,,,,,,,,,,
    2110,2110,0,0,,0,0,1,0,0,0,0,1,1,1,1,1,1601,1601,,9.500000,1,2015-05-29,,,,,,,,,,,,,,,,,,,,,,,,
    6900,6900,0,0,,1,0,1,1,0,0,0,0,0,0,0,0,1107,1107,,1.369000,1,2025-09-23,,,,,,,,,,,,,,,,,,,,,,,,
    8755,8755,0,0,,1,0,1,1,0,0,0,0,0,0,0,0,1107,1107,,3.232000,1,2025-05-22,,,,,,,,,,,,,,,,,,,,,,,,

*File2:*

Code:
    5372,4074,,,,,2,,,
    2110,4100,,,,,0,,,
    6900,5246,,,,,0,,,
    8755,5270,,,,,0,,,

*File3:*

Code:
    2187,2500
    2188,1500
    4227,2000
    5270,3000

Noting that the `NF` for *File1*, *File2* and *File3* is `47`, `10` and `2` respectively.

The need is to check the records from File2 that have $4=2025, for these records we need to match $1 from File2 with $1 from File1, and for the matched records, change the value of $21 in File1 to be $21=$21*1000
then compare it with $2 of File3, if it is equal or greater print $0

The expected output for above files:

Code:
8755

I have tried the following code:

Code:
    awk -F"," '{
        if (NF==47) {
            if ($23 ~ /2025/) {$21=$21*1000}
            {A[$1]=$0}
        } else {
            if (NF==10) {
                if (A[$1]==$0) {B[$1]=$0}
            }
            {if (NF==2) {
                B[$1]==$0 && $21>=$2
            }
            {print $0}
        }
    }'

but the outputs always were *empty records*

Please Advise.
# 2  
Old 07-27-2015
You have shown us 3 input files, and you have shown us non-working code, and you have shown us the output you want.

So, that just leaves us with the question: What logic should be used to extract the value 8755 from those three input files?
# 3  
Old 07-27-2015
For the given input samples, I can't see how the output 8755 could possibly be produced.
File2 does not have any non-empty $4, even less one that holds 2025, none of File1's $21*1000 matches any $2 of File3, and no print $0 would output a single integer only.

---------- Post updated at 11:18 ---------- Previous update was at 11:16 ----------

Please step back and create a precise, detailed specification backed by meaningful input and output samples.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

If else in awk program

Hi All , I have set of input files with one of the fields as below File 1 -Field 1=BUDGET_CURR_FX File 2 -Field 1=BUDGET_MTH_AVGFX File 3 -Field 1=BUDGET_PREV Now i need to include one extra field in the new file as below Output File 1 -Field 1= BUDGET Field2=CURRENT_FX Output File... (2 Replies)
Discussion started by: Hypesslearner
2 Replies

2. Shell Programming and Scripting

Help with awk program

i have two files, one looks like this (file1): novelMiR_892 novelMiR_891, novelMiR_852 novelMiR_893 novelMiR_1661 novelMiR_854 novelMiR_1210 novelMiR_1251 novelMiR_855 novelMiR_1252 novelMiR_897 novelMiR_2336,novelMiR_2335,and the second like this... (5 Replies)
Discussion started by: dietmar13
5 Replies

3. Shell Programming and Scripting

Read files in shell script code and run a C program on those files

HI, I am trying to implement a simple shell script program that does not make use of ls or find commands as they are quite expensive on very large sets of files. So, I am trying to generate the file list myself. What I am trying to do is this: 1. Generate a file name using shell script, for... (2 Replies)
Discussion started by: shoaibjameel123
2 Replies

4. Shell Programming and Scripting

awk program to join 2 fields of different files

Hello Friends, I just need a small help, I need an awk program which can join 2 fields of different files which are having one common field into one file. File - 1 FileName~Size File- 2 FileName~Date I need the output file in the following way O/P- File FileName~Date~Size For... (4 Replies)
Discussion started by: abhisheksunkari
4 Replies

5. UNIX for Dummies Questions & Answers

write a program in c in unix that display the files(includ sub-direc and files within) in a sorted

the sorting is based on name of file, file size modification time stamps o f file it should dislay the output in the following format "." and ".." enteries should be ignored please give some idea how to do it (1 Reply)
Discussion started by: pappu kumar jha
1 Replies

6. Shell Programming and Scripting

AWK program....

Dear All, facing problem to get data in different fields. SO i am using # to get the data.. please refer my code below... BEGIN { FS=" " } { if ( $1 == "START" ) { i = i+1; SFILENAME = FILENAME } if ( substr($1,2,8) == "filename" ) ... (1 Reply)
Discussion started by: arvindng
1 Replies

7. Shell Programming and Scripting

Problem with awk awk: program limit exceeded: sprintf buffer size=1020

Hi I have many problems with a script. I have a script that formats a text file but always prints the same error when i try to execute it The code is that: { if (NF==17){ print $0 }else{ fields=NF; all=$0; while... (2 Replies)
Discussion started by: fate
2 Replies

8. Shell Programming and Scripting

AWK Shell Program to Split Large Files

Hi, I need some help creating a tidy shell program with awk or other language that will split large length files efficiently. Here is an example dump: <A001_MAIL.DAT> 0001 Ronald McDonald 01 H81 0002 Elmo St. Elmo 02 H82 0003 Cookie Monster 01 H81 0004 Oscar ... (16 Replies)
Discussion started by: mkastin
16 Replies

9. Shell Programming and Scripting

AWK program

Hi all, I have the following problem and hope someone could help me. I have 184 files, each with 5 columns (c1, c2, c3, c4, c5). I am only interrested in column 5, and would like to paste column 5 from all the 184 files into one file. I have tried the following with two files awk... (20 Replies)
Discussion started by: awkliker
20 Replies

10. UNIX for Dummies Questions & Answers

AWK Program

:(Hi all, I have a doubt in AWK program. I am writing an awk program which accepts a parameter as input and it should display the corresponding details. if the country as "US" it should be displayed as "United States of America" and the country as "IN" India should be displayed. How can I... (2 Replies)
Discussion started by: sivakumar.rj
2 Replies
Login or Register to Ask a Question