awk assign output of array to specific field-number


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk assign output of array to specific field-number
# 1  
Old 05-07-2012
awk assign output of array to specific field-number

With this script i want to print the output to a specific field-number . Can anybody help?

Code:
awk 'NR=FNR{split(FILENAME,fn,"_");nr[$1]=$2;f = $1} END{for (i=1;i<=f;i++) print i,$fn[2]=nr[i]}' input_5.csv input_6.csv

input_5.csv
Code:
4 135
5 185
6 85
11 30

input_6.csv
Code:
1 90
3 58
4 135
7 60
8 55
10 63

output.csv
Code:
nr     $5  $6
1     90
2
3     58
4    135   135
5    185
6     85
7           60
8           55
9
10          63
11    30

# 2  
Old 05-07-2012
Code:
$ cat fmrg.awk

!F { F=FILENAME; FILENUM=1 }
F != FILENAME { FILENUM++; F=FILENAME }

{
        if((!MIN) ||(MIN>$1)) MIN=$1
        if((!MAX) ||(MAX<$1)) MAX=$1
        R[$1]++; A[$1,FILENUM]=$2
}

END {
        for(X=MIN; X<=MAX; X++)
        {
                printf("%s", X);
                for(N=1; N<=FILENUM; N++)       printf("\t%s", A[X, N]);
                printf("\n");
        }
}

$ $ awk -f fmrg.awk input_6.csv input_5.csv
1       90
2
3       58
4       135     135
5               185
6               85
7       60
8       55
9
10      63
11              30

$


Last edited by Corona688; 05-07-2012 at 05:30 PM..
This User Gave Thanks to Corona688 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to create separate files but not include specific field in output

I am trying to use awk to create (in this example) 3 seperate text file from the unique id in $1 in file, if it starts with the pattern aa. The contents of each row is used to populate each text file except for $1 which is not needed. It seems I am close but not quite get there. Thank you :). ... (3 Replies)
Discussion started by: cmccabe
3 Replies

2. Shell Programming and Scripting

awk to assign points to variables based on conditions and update specific field

I have been reading old posts and trying to come up with a solution for the below: Use a tab-delimited input file to assign point to variables that are used to update a specific field, Rank. I really couldn't find too much in the way of assigning points to variable, but made an attempt at an awk... (4 Replies)
Discussion started by: cmccabe
4 Replies

3. Shell Programming and Scripting

Reverse specific field number

Hello everybody :) I have specific problem when i use rev | uniq -f 3 -c | revORIGINAL Output- (without rev | uniq -f 3 -c | rev) tibenska13 Oct 30 00:26firsth revOUTPUT- 62:00 03 tcO 31aksnebitafter uniq -f 3 -cOUTPUT- 19 62:00 03 tcO 31aksnebitafter next revOUTPUT- tibenska13 Oct 30 00:26... (7 Replies)
Discussion started by: netsys
7 Replies

4. Shell Programming and Scripting

awk to find number in a field then print the line and the number

Hi I want to use awk to match where field 3 contains a number within string - then print the line and just the number as a new field. The source file is pipe delimited and looks something like 1|net|ABC Letr1|1530||| 1|net|EXP_1040 ABC|1121||| 1|net|EXP_TG1224|1122||| 1|net|R_North|1123|||... (5 Replies)
Discussion started by: Mudshark
5 Replies

5. Shell Programming and Scripting

How to Assign an shell array to awk array?

Hello All, Can you please help me with the below. #!/bin/bash ARR="No Differences In Stage Between HASH_TOTALS & HASH_TOTALS_COMP For UNINUM:0722075 PROVIDER:5 EXTRACT_DT:30-SEP-12 VER_NUM:1" ARR="No Differences In Stage Between HASH_TOTALS & HASH_TOTALS_COMP For UNINUM:0722075 PROVIDER:5... (14 Replies)
Discussion started by: Ariean
14 Replies

6. Shell Programming and Scripting

How to print with awk specific field different from specific character?

Hello, i need help with awk. I have this file: cat number DirB port 67 er_enc_out 0 er_bad_os 0 DirB port 71 er_enc_out 56 er_bad_os 0 DirB port 74 er_enc_out 0 er_bad_os 0 DirB port 75 ... (4 Replies)
Discussion started by: elilmal
4 Replies

7. Shell Programming and Scripting

Replace specific field on specific line sed or awk

I'm trying to update a text file via sed/awk, after a lot of searching I still can't find a code snippet that I can get to work. Brief overview: I have user input a line to a variable, I then find a specific value in this line 10th field in this case. After asking for new input and doing some... (14 Replies)
Discussion started by: crownedzero
14 Replies

8. Shell Programming and Scripting

Assign zero to strings that don't appear in block, store result in AWK array

Hi to all, I have this input: <group> <x "2">Group D</x> <x "3">Group B</x> <x "1">Group A</x> </group> <group> <x "1">Group E</x> <x "0">Group B</x> <x "1">Group C</x> </group> <group> ... (11 Replies)
Discussion started by: Ophiuchus
11 Replies

9. Shell Programming and Scripting

Assign dscl output to variable as an array

Greetings folks, I am trying to assign the output of a dscl command (contains name<spaces>id) to a variable as an array. Currently I am piping the output into a tmp file, then reading the tmp file into an array, then parsing the array. I would like to bypass creating the tmp file portion of... (6 Replies)
Discussion started by: macnetdaemon
6 Replies

10. Shell Programming and Scripting

assign awk array with printf

I am trying to assign a awk array for further processing later in the script. I can't seem to figure it out. If someone could look at this and help me, I would very much appreciate it. Thanks in Advance. for ( x = 1 ; x <= Var ; x++ ) { if ( x in varr ) { ... (2 Replies)
Discussion started by: timj123
2 Replies
Login or Register to Ask a Question