![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Script extracting the incorrect data from text file | jermaine4ever | Shell Programming and Scripting | 6 | 03-16-2009 12:18 PM |
| Incorrect login NIS? | Juterassee | SUN Solaris | 5 | 10-30-2008 11:08 AM |
| login incorrect | espace1000 | UNIX for Dummies Questions & Answers | 2 | 08-22-2008 06:48 AM |
| Login Incorrect | sydney2008 | Red Hat | 6 | 08-22-2008 04:57 AM |
| Incorrect Directory Name | jand102821 | UNIX for Dummies Questions & Answers | 1 | 06-19-2002 04:35 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Awk incorrect data.
I am using the following command:
Code:
nawk -F"," 'NR==FNR {a[$2$3]=$1;next} a[$2$3] {print a[$2$3],$1,$2,$3}' file1 file2
But when i import file1 and file2 in MS Access i get 140 records. And i know 140 is correct count. Appreciate your help on correcting the above script |
|
||||
|
Quote:
I have two files $ head file1 zip,FirstName,Lastname 07777,abc,def 22584,dec,dlo 25487,xyz,jkl 25488,dim,kio $ head file2 aim server database SSN,Firstname,LastName 123456789,abc,def 123456789,dec,dlo 123456789,xyz,jkl 123456789,dim,kio wanted Output: SSN,zip,FirstName,LastName Code:
nawk -F"," 'NR==FNR {a[$2,$3]=$1;next} ($2 SUBSEP $3) in a {print a[$2,$3],$1,$2,$3}' OFS=, " file2 file1
40 Matches
Code:
nawk -F"," 'NR==FNR {a[$2,$3]=$1;next} ($2 SUBSEP $3) in a {print a[$2,$3],$1,$2,$3}' OFS=, " file1 file2
140 matches
Can you please explain this part ($2 SUBSEP $3) a[$2,$3] we are using , here because its is comma seperated inputfile or is it general rule If i dont use , then also i am getting same result |
|
|||||
|
Quote:
Also I don't understand why you have a trailing double quote (in red) in both case? Quote:
Code:
a[$2,$3] The originally posted solution should give you the desired result. Given file1: Code:
zip,FirstName,Lastname 07777,abc,def 22584,dec,dlo 25487,xyz,jkl 25488,dim,kio Code:
SSN,Firstname,LastName 123456789,abc,def 123456789,dec,dlo 123456789,xyz,jkl 123456789,dim,kio Code:
nawk -F, 'NR==FNR {a[$2,$3]=$1;next} ($2 SUBSEP $3) in a {print a[$2,$3],$1,$2,$3}' OFS=, file2 file1
Code:
123456789,07777,abc,def 123456789,22584,dec,dlo 123456789,25487,xyz,jkl 123456789,25488,dim,kio Also, this is NOT one of your first forum posts and you've been asked in the past: please use BB Code tags when posting data or code samples. |
|
||||
|
Quote:
Code:
nawk -F"," 'NR==FNR {a[$2,$3]=$1;next} ($2 SUBSEP $3) in a {print a[$2,$3],$1,$2,$3}' OFS=, file1 file2
I cannot post the files due to data sensitivity. I visually checked the files and i see no special characters or anything. Is there a special command to verify this. Appreciate your response. |
|
|||||
|
Quote:
Doctor: Then don't do that! The positions of the files on the command line is important for mapping the fields from one file to the other. Look at your data files' fields - try to see the difference and look at your original posting for the mapping logic. Good luck. |
| Sponsored Links | ||
|
|