matching names in 2 text files


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
# 1  
matching names in 2 text files

I have 2 text files like

________________________________

Company Name:yada yada
ADDRESS:some where, CITY,STATE
CONTACT PEOPLE:first_name1.last_name1,first_name2.last_name2,first_name3.last_name3
LEAD:first_name.last_name
________________________________
&

Data file2
______________________________
COMPANY NAME1:first_name.last_name, first_name1.last_name1,first_name2.last_name2,first_name3.last_name3
COMPANY NAME2:first_name4.last_name4, first_name5.last_name6,first_name7.last_name7,first_name8.last_name8


____________________________


I need to validate people(Bold) in

CONTACT PEOPLE:first_name1.last_name1,first_name2.last_name2,first_name3.last_name3
LEAD:first_name.last_name

against datafile 2 and make sure names in both files match.
(We can assume no name repetitions in data file2 )

i,e. .. I need to grep for each name in file1 against file2

Thank you all for your time

Last edited by rider29; 08-27-2009 at 05:58 PM..
# 2  
If you are just wanting to see if all the names liste in the first file are present in the second one:
Code:
for name in `egrep '^(CONTACT PEOPLE:|LEAD:) datafile1 | cut -d ':' -f 2 | sed 's/,/ /g'`
do
  if grep $name datafile2 > /dev/null
  then
    echo "$name validated"
  else
    echo "$name NOT VALIDATED"
  fi
done

(untested - try this somewhere safe and you may need to debug)
egrep is dependent on OS, if it's not present, try substituting with grep -e
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #179
Difficulty: Easy
The Apple I first went on sale in July 1976 and sold for $666 USD.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Print matching fields (if they exist) from two text files

Hi everyone, Given two files (test1 and test2) with the following contents: test1: 80263760,I71 80267369,M44 80274628,L77 80276793,I32 80277390,K05 80277391,I06 80279206,I43 80279859,K37 80279866,K35 80279867,J16 80280346,I14and test2: 80263760,PT18 80279867,PT01I need to do some... (3 Replies)
Discussion started by: gacanepa
3 Replies

2. UNIX for Dummies Questions & Answers

find command: names matching the expression

Hello all, I need to print directories using find command. The directories names contain date in the format YYYYMMDD or the name of directory is only the date format. I want print directories, which doesn't start with this date. E.g I have dirs like foo20120101 foo20120101foo 20120101foo... (1 Reply)
Discussion started by: satin1321
1 Replies

3. Shell Programming and Scripting

How to find empty files in a directory and write their file names in a text?

I need to find empty files in a directory and write them into a text file. Directory will contain old files as well, i need to get the empty files for the last one hour only. (1 Reply)
Discussion started by: vel4ever
1 Replies

4. Shell Programming and Scripting

Removing files with same text but different file names

Hi All, I have some 50,000 HTML files in a directory. The problem is; some HTML files are duplicate versions that is wget crawled them two times and gave them file names by appending 1, 2, 3 etc after each crawl. For example, if the file index.html has been crawled several times, it has been... (1 Reply)
Discussion started by: shoaibjameel123
1 Replies

5. Shell Programming and Scripting

How to remove common file names from text files

I'm running on freebsd -- with a default shell of csh. I have two files named A and B. Each line of each file contains a file name. How can I write a script that removes all the file names in file B from A. I tried to use perl to create a huge regular expression with "|" separating the file... (2 Replies)
Discussion started by: siegfried
2 Replies

6. Shell Programming and Scripting

Removing matching text from multiple files with a shell script

Hello all, I am in need of assistance in creating a script that will remove a specified block of text from multiple .htaccess files. (roughly 1000 files) I am attempting to help with a project to clean up a linux server that has a series of unwanted url rewrites in place, as well as some... (4 Replies)
Discussion started by: boxx
4 Replies

7. Shell Programming and Scripting

matching and extracting info from text files

Hi all, I have two .txt file i.e. First text file: 2 4 1 4 Second text file 2 1.nii.gz 4 334.nii.gz 1 12.nii.gz 4 134.nii.gz If entry in 1st column of 1st text file matches the 1st column of 2nd text file, then copy the file (name of which is the second column) associated with... (4 Replies)
Discussion started by: vd24
4 Replies

8. Shell Programming and Scripting

Shell - Matching 3 letter file names

Hi I am running a shell script with bdf command and want to match all files with length 3 inside a specific partitions. How do i do that say for example if i want to list all files with length 3 in /home/jimmy partition, bdf /home/jimmy the output i need is xyx abc yyy amp ... (4 Replies)
Discussion started by: PrasannaKS
4 Replies

9. Shell Programming and Scripting

processing file names using text files

Hi, I have to perform an iterative function on a set of 10 files. After the first round the output files are named differently than the input files. examples input file name = xxxx1.yyy output file name = xxxx1_0001.yyy I need to rename all of the output files to the original input... (5 Replies)
Discussion started by: ligander
5 Replies

10. AIX

Simultaneous searching for files (names matching certain criteria) in several directo

Hello everyone, My OS is AIX 5.2 I would like some help in getting command syntax that does the following: 1. Searches simultaneously several directories downward; 2. Checks every subdirectory in each directory (and so on…) for file names that contain certain characters such as “~”, start or... (0 Replies)
Discussion started by: Hopeful
0 Replies

Featured Tech Videos