Don, would you please explain your code.. I plan to build on this in near future. thank you
Hello ritakadm,
Following may help you.
Code:
awk '
BEGIN { FS = OFS = "\t" # Setting Field seperator and Output field seprator as tab
fields[++nf] = 2 # Creating an array named fields whose index is nf (which has values 1, 2 up to 3) and value is 2, 3 and 4
fields[++nf] = 3 # Assigning 2nd element as value 3 whose index is 2
fields[++nf] = 4 # Assigning 3rd element to array fields whose index is 3
}
FNR == 1 { # This condition will be TRUE whenever it reads a new file
f++ # increasing variable f's value by 1
}
f <= nf {l[f, $1] = $2 # Checking condition here where variable f is less than and equal to variable nf's value, making array named l whose index is variable f and $1, setting it's value to $2, eg. l(1, 1)=a b
next # skipping other actions
}
{ for(i = nf; i > 0; i--) { # intilizing for loop from variable nf's value to 0
n = split($fields[i], sf, " ") # creating an array named sf whose seperator is space and taking it's count to variable n
af = OFS # setting a variable named af's value to OFS(Output field seprator)
for(j = 1; j <= n; j++) # intilizing a for loop whcih will run till variable j's value is equal to n's value
af = af l[i, sf[j]] ((j < n) ? " " : "") # setting value of af here eg. (af = af l(3, sf(1)) " ") which is actually [af=af 10 ] then (af = af l(3, sf(2)) " ") which is actually [af=af 10 20]
$fields[i] = $fields[i] af # Setting individual field's value in line by fields array
}
}
1' Lookup2 Lookup3 Lookup4 file # 1 means allow defualt action which is print here, filenames are given as input
Hello Don,
I just tried to explain code, kindly do correct me if I have missed something or mentoined anything wrong here.
Thanks,
R. Singh
Last edited by RavinderSingh13; 12-29-2014 at 11:46 AM..
Reason: Tried to editing for comments but didn't happen properly
This User Gave Thanks to RavinderSingh13 For This Post:
Using AIX 5.2, Bourne and Korn Shell.
I have two flat text files. One is a main file and one is a lookup table that contains a number of letter codes and membership numbers as follows:
316707965EGM01
315672908ANM92
Whenever one of these records from the lookup appears in the main file... (6 Replies)
I am trying to transpose tables listed in the format into format. Any help would be greatly appreciated.
Input:
test_data_1
1 2 90%
4 3 91%
5 4 90%
6 5 90%
9 6 90%
test_data_2
3 5 92%
5 4 92%
7 3 93%
9 2 92%
1 1 92%
...
Output:... (7 Replies)
Hi All
I have got a fixed length file of 80bytes long.The first 4bytes of each record represents a client_number.I need to modify the client number based on another lookup file.
The lookup file contains 2 fields and a comma delimited file.The first line of the lookup file contains the header... (5 Replies)
Write a quick shell snippet to find all of the IPV4 IP addresses
in any and all of the files under /var/lib/output/*, ignoring
whatever else may be in those files. Perform a reverse lookup on
each, and format the output neatly, like "IP=192.168.0.1,
... (0 Replies)
hey guys,
can anybody help me out here on the following:
grep '^\{1,3\}\.\{1,3\}\.\{1,3\}\.\{1,3\}$' ravi.txt mary.txt lisa.txt https://www.unix.com/images/misc/progress.gif
i.e what i did was found ip addreses from different files
and then i want... (1 Reply)
I have a lookup file in unix say /data/lkp.dat (First line is header and space delimited) and the content is shown below.
Another file which contains the job_name and rec_count lets say /data/data_file.dat(no header pipe delimited file).
Now i want to do a lookup on job_name and my output should... (3 Replies)
To give you some context of my issue the following is some sample dummy data. The field delimiter is "<-->". The 4th field is going to be tags for my notes. The tags should always be unique and sorted alphabetically.
1<-->01/20/12<-->01/20/12<-->1st note<-->1st note<-NL->2 lines... (4 Replies)
hello masters,
I am working with csv files that open just fine in excel, but have sub-fields which are comma separated as well.
a 3 column csv looks like
a,b,"c,d,e"
f,g,h
How do I make join or sort believe that "c,d,e" is just 1 field? (8 Replies)
Hello experts,
I have a file looking like
v1 g1 5.42
v2 g1 2.43
v1 g2 1.24
v3 g2 0.6
I want to lookup the first value in another sorted table which is greater than column 3 value, keying on column 2 on the first table.
The sorted table looks like the following,. where I want to find... (3 Replies)