thanks a ton!! Yes it correct now.. the code is a liitle difficult for my level of expertise I havent used arrays much.. If you can help me underatnad it a little i would appreciate it,
the reason i ask is i must be able to modify it,... what if they want the summary as well i must be able to add those lines with some dummy date or with date blank..
While reading the first non-empty input file (NR == FNR) do:
- remove the first field (assuming a default FS)
- store the rest of the current record in an associative array named r, keyed by FNR.
- mark the record as processed (no further actions will operate on those records).
When the expressions !t[$1]++ (a common AWK idiom that means "when the key value is seen for the first time", i. e. when the value of $1 changes [actually this part could be rewritten in a more efficient way given your file is already sorted - you don't need an array here] and (&& - logical AND) FNR is greater than 1 do:
- print all but the last 6 values of the array named l concatenating to them the values of the r array (see below) incrementing the index if the value of the l array matches the string Total and if the counter variable c is used for the first time. This is the part of the code that prints the above:
- set i and j to 0/false
- delete the l array, if your AWK implementation supports the delete function to delete the entire array, use that function instead:
Build an array l keyed by the auto-incremented variable i and store the entire record (here we are reading the second input file) as value.
Because we actually output the lines when the value of the first field changes, we need to repeat the loop for the last section in the END block.
thank you so much.. i understand it much better now.. however i do have some basic questions..
NR == FNR this condition I am little confused..
While reading the first non-empty input file (NR == FNR)
What is being stored in the array r is the rest of the record minus the key (filename in this case) .. so what is
r[FNR] how is FNR pointing to the key?
agina here !t[$1]++ && FNR > 1
again here what is FNR.. i guess i do not know the basic FNR definition..
I have two directories, each have 27 files with same name and now I want to combine them one by one into another directory with same names.
I dont know how to use "and" for the "for loop" so it will not go in the circle.
so my code has a problem I dont know how to fix :wall::wall::wall::wall:... (15 Replies)
Hi I have about 108 files (text files) that end with .avg and each one of these files have a distinct name that describes what is in the file. In each file there is a set of 80 values that are tab separated. I want to combine all 108 files into ONE main file.
So each file is named:
1.avg... (5 Replies)
i am having 2 files like this
file 1
1,
2,
3,
4,
file2
5,
6,
7,
8,
what i want do is like this
i want to put all the contents for file 2 after file 1,means adding column in file1 (5 Replies)
Hi All,
Request your expertise in tackling one requirement in my project,(i dont have much expertise in Shell Scripting). The requirement is as below,
1) We store the last run date of a process in a file. When the batch run the next time, it should read this file, get the last run date from... (1 Reply)
Hi there,
I have two files. What I want to do is search for the values in second field of file1 in the 6th field of the file2 and of they match to add the fields 1-5 of the file2 at the end of the line of file1 with a comma before.
E.g
File1
FWB,CHUAGT87HUMAS/BUD01,REUAIR08KLM... (3 Replies)
I have two files and I need to combine (not append - but combine a row to a row)
eg:
File1:
apples
grapes
oranges
lemons
File2:
red
green
orange
yellow
After combining, the file should look like: (the second column should start at a specific byte)
apples red
grapes green... (7 Replies)
Could someone help me reduce the number of runs for a shell program I created?
I have two text files below:
$ more list1.txt
01 AAA
02 BBB
03 CCC
04 DDD
$ more list2.txt
01 EEE
02 FFF
03 GGG
I want to combine the lines with the same number to get the below:
01 AAA 01 EEE
02... (4 Replies)
I have two files which contain data from two different transactions in the same format:
<Name> - <Count>
My goal is to end up with data in this format after combining the two:
<Name> - <Count1> - <Count2>
Is this possible to do with awk, or is there something better?
Thanks... (3 Replies)
Hi,
is there a way to combine 2 files together, joining line 1 from file A with line 1 from file B, line 2 from A with line 2 from B etc.
File A File B
1 4
2 5
3 6
Combined result =
File C
14
25
36 (2 Replies)
how will i combine these 2 files below, with the desired output
specified below:
file1:
one
two
three
four
file2:
red
blue
yellow
green
file3:
aaa
bbb
ccc
ddd (3 Replies)