mappin strings of two different file and finding the mapped string and then map other fields.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting mappin strings of two different file and finding the mapped string and then map other fields.
# 1  
Old 03-16-2011
mappin strings of two different file and finding the mapped string and then map other fields.

As i am new to unix so facing some problems in scripting:
here is my question:
i m having two files. 1st file say a.txt contain 3 column like
Code:
SPECIALITY|UMP_CODE|SPECIALTY_CODE
Addictive Diseases|25ADD|ADD
Addictive Diseases/Family Practice|25ADD|ADD/FP
Aerospace Medicine|1.041666667|AM
Aerospace Medicine/Family Practice|1.041666667|AM/FP
Allergy & Immunology|01AI|AI
Allergy & Immunology/Pulmonary Medicine|01AI|AI/PUL
Anatomic Pathology & Laboratory Medicine|17APL|APL
Cardiology|03C|C
Cardiology/Internal Medicine|03C|C/

and 2nd file let say b.txt contain only one column speciality:
Code:
Speciality
Abdominal
ADDICTION MEDICINE
ALLERGY
Adolescent Medicine
Family Practice
General Practice

so i want to map b.txt file column, speciality with the a.txt file and after mapping of the strings i want to get the UMP_CODE of the respected feilds also which mapped in both column. i want to assign variables name( a = &Family Practice) so that i change the fields as it is changing in every file.
my output is like this:
Code:
SPECIALITY UMP_CODE
    Aerospace Medicine 1.041666667
    Addictive Diseases 03C
    Cardiology 03C
    Family Practice 07FP
    Allergy & Immunology 01A

So thanks for any kind of help.Smilie

Moderator's Comments:
Mod Comment Please use [code] and [/code] tags when posting code, data or logs etc. to preserve formatting and enhance readability, thanks.

Last edited by zaxxon; 03-16-2011 at 08:36 AM.. Reason: code tags
# 2  
Old 03-16-2011
Try:
Code:
awk -F\| 'BEGIN{print "SPECIALITY UMP_CODE"}NR>1 && NR==FNR{a[$0];next}$1 in a{print $1,$2}' b.txt a.txt

# 3  
Old 03-16-2011
sorry to say but the code is not working it is showing the error:
can't open the source file "|" for reading.
# 4  
Old 03-16-2011
What operating system are you using?
# 5  
Old 03-17-2011
i m using unix operating system( bash)

---------- Post updated at 11:12 AM ---------- Previous update was at 10:46 AM ----------

hey its ok i made it work by myself.....
my code is like this

Code:
awk ' BEGIN { FS="|";
while ( getline < "all_spec.txt" > 0)
   a[$1]=$2
}
{
if($1 in a)
    printf("%s %s\n", $1, a[$1])
} ' sample.txt

but as i said you earlier i am new to UNIX so having a lot of questions in my mind,
and lot of doubts. one of them is like as in normal programming we declare variables
and later use those variables in our function and loops,in the same way i want to declare variable and can use it inside the script.
Like i want to assign my b.txt fields as variable as a= General Practice, b= Family practice
and later can use in the script. Is it possible if it is then help me on
this program how to do this by declaring variables in the above codes.
so rply as soon as possible..................

Last edited by dsh007; 03-18-2011 at 06:04 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Getting string from a File between 2 well known strings.

Hi, I have a file server1.log with following lines. 00002b77 ThreadMonitor W WSVR0605W: Thread "WebContainer : 2" (00000046) has been active for 542865 milliseconds and may be hung. There is/are 3 thread(s) in total in the server that may be hung. I want to find out how many threads are... (2 Replies)
Discussion started by: jayeshusa
2 Replies

2. Shell Programming and Scripting

Finding Strings between 2 characters in a file

Hi All, Assuming i have got a file test.dat which has contains as follows: Unix = abc def fgt jug 111 2222 3333 Linux = gggg pppp qqq C# = ccc ffff llll I would like to traverse through the file, get the 1st occurance of "=" and then need to get the sting... (22 Replies)
Discussion started by: rtagarra
22 Replies

3. Shell Programming and Scripting

Finding a string in a file

Hello All, I have a text file, i want to search for a string in it and the string is repeated multiple times in a file i want to get the first occurence of the string in a variable. the content of file is like: I want to grepthe first occurance of "Configuration flow done" and store the... (7 Replies)
Discussion started by: anand2308
7 Replies

4. Shell Programming and Scripting

Finding/replacing strings in some files based on a file

Hi, We have a file (e.g. a .csv file, but could be any other format), with 2 columns: the old value and the new value. We need to modify all the files within the current directory (including subdirectories), so find and replace the contents found in the first column within the file, with the... (9 Replies)
Discussion started by: Talkabout
9 Replies

5. UNIX for Dummies Questions & Answers

Finding files with a certain name string inside of another file.

Hi, I have a very large file that contains a listing of all files on the system. I need to create a listing from that file of all files that start with the following format: s???_*, whereas the '?' represents characters, so the file name begins with an 's' followed by three other characters and... (4 Replies)
Discussion started by: tes218
4 Replies

6. Shell Programming and Scripting

grep a string in the lines between 2 strings of a file

Hi , Please help me with the following problem: I have an xml file with the following lines <cisco:name> <cisco:mdNm>Cisco Device 7500 A Series</cisco:mdNm> <cisco:meNm>10.1.100.19</cisco:meNm> <cisco:ehNm>/shelf=1</cisco:ehNm> <cisco:subname> <cisco:sptp>Cisco PortA... (8 Replies)
Discussion started by: bhagirathi
8 Replies

7. Shell Programming and Scripting

Need help with finding unique string in log file

Shell script help Here is 3 sample lines from a log file <date> INFO <java.com.blah> abcd:ID= user login <date> DEBUG <java.com.blah> <nlah bla> abcd:ID=123 user login <date> INFO <java.com.blah> abcd:ID=3243 user login I want to find unique "ID" from this log... (3 Replies)
Discussion started by: gubbu
3 Replies

8. UNIX for Advanced & Expert Users

finding a string in a file

hi all.. I dont know how to search for a string in a file.. I have tried doing.. I did google but didnt get effective answers..my code is as follows: int search(char* filename,const char* username,const char* passwd) { int flag=0; unsigned long fsize=0; unsigned long current=0;... (2 Replies)
Discussion started by: Ume1986
2 Replies

9. Shell Programming and Scripting

Finding a certain string on each line in a file

Hi, I need a script to get every line from a file where there are less then 17 ; on a line. Thank's (5 Replies)
Discussion started by: VODAFUN
5 Replies
Login or Register to Ask a Question