![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | 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 here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| To call/execute a shell script from a shell script | konark | UNIX for Dummies Questions & Answers | 1 | 10-26-2007 02:16 PM |
| How to pass a parameter from one Shell-script to another Shell-script | subodhbansal | Shell Programming and Scripting | 2 | 09-22-2007 02:19 AM |
| How to Run a shell script from Perl script in Parent shell? | hifake | Shell Programming and Scripting | 16 | 08-28-2007 05:42 PM |
| Accessing variables of one shell script in another shell script | rsendhilmani | Shell Programming and Scripting | 1 | 04-30-2007 05:43 AM |
| Have a shell script call another shell script and exit | heprox | Shell Programming and Scripting | 2 | 11-20-2006 04:17 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
Shell Script using awk
File1
9000|9000|WW|1|1|SL|472|472|LC|2272|1072|MTY 9000|9000|WW|1|1|SL|470|470|MC|1270|1172|MPVT 9000|9000|WW|1|1|SL|472|472|LC|1072|1672|MBD 9000|9000|WW|1|1|SL|473|473|LF|1173|1173|MTY File2 DPT.1072 CP~ Apr 1514283.914 DPT.1172 CP~ Apr 967882.506 DPT.1672 CP~ Apr 545199.000 DPT.1772 CP~ Apr 912656.817 Compare the column 11 of file 1 with the 1st column of file2. The 1st column of file2 contains a prefix dpt. also. We need to compare file2 with file1 and in the output we should get all the values from file2 that are present in file1. We should not remove dpt. from the output. It will always be 8 characters in 1st column of file2 (e.g DPT.1072). The output should be: DPT.1072 CP~ Apr 1514283.914 DPT.1172 CP~ Apr 967882.506 DPT.1672 CP~ Apr 545199.000 I am thankful for your help. |
| Forum Sponsor | ||
|
|
|
|||
|
Thanks for your reply. I will try this. Only thing I am not sure is the prefix DPT. in file2. We want to compare two files after removing prefix DPT. but we do NOT want to remove DPT. from the output. Means in the comparsion command only we need to compare without DPT.---------May be at the time of comparsion something like substr(col1 of file2, 4,8)...........
Thanks Much. |
|
|||
|
Code:
awk -F"|" 'FNR==NR {a[$11]++; next} a[substr($0, 5, 4)] {print}' file1 file2
FNR==NR {a[$11]++; next} buid an array with 11th field of file1 and give value 1 (default value 0+1) to it. a[substr($0, 5, 4)] {print} if a[nnnn] is TRUE (1)---> print line from file2 |