How do i search for the contents of list1 in list2?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How do i search for the contents of list1 in list2?
# 1  
Old 11-26-2009
How do i search for the contents of list1 in list2?

hello all,
I have 2 files, list1 and list2.
They can each have several thousand lines each.

I want to check if list2 has any of the contents of list1, perhaps using a grep so that for instance if list1 contained

arb1000

and list2 contained

arb1000tt

It would match this and pipe it out to seperate file, list3.

I have tried a foreach loop but i get error message, "Too many words from ``" and having looked in the forums I am now not even sure if that was the best way of going about it.

Anybody able to advise what the best way to do this sort of thing is?

Many Thanks
# 2  
Old 11-26-2009
Try:

Code:
grep -f list1 <list2 >list3

# 3  
Old 11-26-2009
hi thanks but i receive a message :

grep: illegal option -- f
Usage: grep -hblcnsviw pattern file . . .

should have mentioned I am using a c shell in solaris.

cheers
# 4  
Old 11-29-2009
Having read these forums I have now realised that the either of the following seem to do the job :

/usr/xpg4/bin/grep -f file1 < file2

or

egrep -f file1 < file2

I will have to learn the uses of egrep and I am not sure why there seems to be two grep commands but I guess thats the problem with me being a unix newbie Smilie

Thanks to all
Cheers
# 5  
Old 02-23-2010
MySQL

Using vimdiff command we can find out the difference if it is a small file.

if the file has n number of lines then the vimdiff command is not good.
# 6  
Old 02-23-2010
MySQL -f option

I am using grep 2.5.1 .In that,

Code:
grep -f list1 <list2 >list3

is not showing any error.This is the option to compare contents of a file with some other files.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

If contents of A are in B then move the common contents to C

Hallo Team, I have 2 .csv files file A has 47600 lines and file B has 67000 lines FILEA SD0o9rb01-1d320ddbcc8d220f572739ebed5f58d1-v300g00 SD8bt0101-a0810bfe0e3396060126ec51b30dac0a-v300g00 SD05sce01-cb056af347ed4651f29eb3c3e9addbd6-v300g00... (3 Replies)
Discussion started by: kekanap
3 Replies

2. Shell Programming and Scripting

Search for a particular file and then cat its contents

Hi Friends, I am looking for a particular file abc* for today's date and then i want to cat its contents to another variable. How to do this. The first step has been accomplished i.e. searching for that file. Now i want to cat the result of this output i.e. abc.txt bash-3.2$ ls -l... (4 Replies)
Discussion started by: srkmish
4 Replies

3. Shell Programming and Scripting

Folder contents getting appended as strings while redirecting file contents to a variable

Hi one of the output of the command is as below # sed -n "/CCM-ResourceHealthCheck:/,/---------/{/CCM-ResourceHealthCheck:/d;/---------/d;p;}" Automation.OutputZ$zoneCounter | sed 's/$/<br>/' Resource List : <br> *************************** 1. row ***************************<br> ... (2 Replies)
Discussion started by: vivek d r
2 Replies

4. Shell Programming and Scripting

search for a date and print the contents below the line

Hi, We have a script which takes the backup of some files and writes the output into a log file for each run on a daily basis. Following is the extract from the log file. Date:20120917 ********************************************************** * BACKUP ACTIVITY STARTED ... (5 Replies)
Discussion started by: svajhala
5 Replies

5. Shell Programming and Scripting

Read from "list1" and list matches in "list2"

I want to print any matching IP addresse in List1 with List 2; List 1 List of IP addresses; 161.85.58.210 250.57.15.129 217.23.162.249 74.76.129.101 30.221.177.237 3.147.200.59 170.58.142.64 127.65.109.33 150.167.242.146 223.3.20.186 25.181.180.99 2.55.199.32 (3 Replies)
Discussion started by: lewk
3 Replies

6. Shell Programming and Scripting

Replace partial contents of file with contents read from other file

Hi, I am facing issue while reading data from a file in UNIX. my requirement is to compare two files and for the text pattern matching in the 1st file, replace the contents in second file by the contents of first file from start to the end and write the contents to thrid file. i am able to... (2 Replies)
Discussion started by: seeki
2 Replies

7. UNIX for Dummies Questions & Answers

How to search two strings in a file and print the contents in between to a file

I have a file called po.txt. Here is the content of the file: <!DOCTYPE PurchaseOrderMessage (View Source for full doctype...)> - <PurchaseOrder> - <Header> <MessageId>cdb3062b-685b-4cd5-9633-013186750e10</MessageId> <Timestamp>2011-08-01T13:47:23.536-04:00</Timestamp> </Header> -... (4 Replies)
Discussion started by: webbi
4 Replies

8. UNIX for Dummies Questions & Answers

search contents of a file and use it to name the file

Hi All! I have text files containing data as follows: file1 file2 file3 file4 abc pqr def ghi 76 43 34 3 43 34 3 23 34 3 89 8 i would like to search the contents of all files for the... (3 Replies)
Discussion started by: chen.xiao.po
3 Replies

9. Shell Programming and Scripting

Search a pattern in a file with contents in a single line

Hi all I am searching for a pattern in a file . The file content is in a single line.If am doing a grep or sed for the a particular pattern am getting whole file. I want the result in different lines. attaching the file for reference search pattern "/xxxxxx/hhhh/tttttttt/sss/" and... (4 Replies)
Discussion started by: sparks
4 Replies

10. Shell Programming and Scripting

search for the contents in many file and print that file using shell script

hello have a file1 H87I Y788O T347U J23U and file2 J23U U887Y I99U T556U file3 I99O J99T F557J file4 N99I T666U R55Y file5 H87I T347U file6 H77U R556Y E44T file7 Y788O K98U H8I May be using script we can use file1 to search for all the files and have the output H87I file5... (3 Replies)
Discussion started by: cdfd123
3 Replies
Login or Register to Ask a Question