how to find out overlaped content


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to find out overlaped content
# 1  
Old 09-23-2008
how to find out overlaped content

i have two single column text files a and b. in this two files, there are some overlap content, is there any quick way I can find out those overlapped content?

example, file a

1
2
3
4
5
6

file b
2
35
7
8
4

2 and 4 are overlapped in these two files so they should be picked up.
# 2  
Old 09-23-2008
Use grep, something like:

Code:
grep -f file1 file2

Regards
# 3  
Old 09-23-2008
Code:
sort -n file1 > sorted1
sort -n file2 > sorted2
comm -12 sorted1 sorted2

# 4  
Old 09-23-2008
Building on shamrock's answer, you could merge this into one line if you're running bash:

comm -12 <(sort file_a) <(sort file_b)

The <( ) construct creates a temporary file out of the output of the command(s) inside the parens.

/fimblo
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Find all files containing string not following symlinks CAT (modified) output content to /filename

This should recursively walk through all dirictories and search for a specified string in all present files, if found output manicured content (eg some regex) with CAT into a specified directory (eg /tmp/) one by one, keeping the original names This is what I have so far, which seems to... (1 Reply)
Discussion started by: lowmaster
1 Replies

2. Shell Programming and Scripting

Find difference in content between two particular lines in two files

I have two files named Before.txt and After.txt: Now i want to find the difference in content between <Marker 1> and <Marker 2> in the two files. ---------- Post updated at 05:00 PM ---------- Previous update was at 04:50 PM ---------- Any help will be highly appreciated..:) (3 Replies)
Discussion started by: proactiveaditya
3 Replies

3. Shell Programming and Scripting

script to find backshash and place the content in next line

Hi All, I am new to the forum and scripting...Can someone help me with a code.. My input file will be like $cat first aa a\b bb\ccccc\ddd ee*e\fff\ggg output should be aa a\ b bb\ ccccc\ ddd ee*e\ fff\ ggg I tried with cat first | awk '{ gsub( /\\/, "/\\/" );... (5 Replies)
Discussion started by: madhanmo
5 Replies

4. Shell Programming and Scripting

how to find a content in all files

Hi, i would like to find 'AppManage' in all files. i have tried the following but it didn't work. /local/home/mani>grep -iR 'AppManage' *.* - not outcome /local/home/mani>grep -iR 'AppManage' - this one hangs thanks (3 Replies)
Discussion started by: lookinginfo
3 Replies

5. Shell Programming and Scripting

Find out the match data content?!

Hi, Long list of Input file1 content: 1285_t 4860_i 4817_v 8288_c 9626_a . . . Long list of Input file2 content: 1285_t chris germany 8288_c steve england 9626_a dave swiss 9260_s stephanie denmark . . . (14 Replies)
Discussion started by: patrick87
14 Replies

6. AIX

find for specific content in file in the directory and list only file names

Hi, I am trying to find the content of file using grep and find command and list only the file names but i am getting entire file list of files in the directory find . -exec grep "test" {} \; -ls Can anyone of you correct this (2 Replies)
Discussion started by: madhu_Jagarapu
2 Replies

7. Shell Programming and Scripting

find and replace in subdirectory (filename & content - both)

Hi, I have to rename all occurance of CUST_MST to RESELLER_MST both in filename and file content under a directory (say D0) which contains multiple (2-3 levels) sub directory. Example: D0 -> D1 -> D2 has a file CUST_MST_TEMP.txt this contains : > cat /D0/D1/D2/CUST_MST_TEMP.txt... (3 Replies)
Discussion started by: sabyasm
3 Replies

8. Shell Programming and Scripting

find content from a file

root 0 0 5 0 11/09/07 08:18 root 0 0 6 0 11/09/07 08:56 root 0 0 7 0 11/22/07 11:09 user1 0 0 8 0 11/08/07 15:58 user2 0 0 9 0 11/30/07 08:37 ... (7 Replies)
Discussion started by: ust
7 Replies

9. UNIX for Dummies Questions & Answers

find the same content in the file

I have two files ( eg. file1 and file2 ) , its contents are as below , I want to find out the same content ( same word ) in the two files , in the below example , the same content is "aaa" , could suggest how to do it ? thx. #vi file1 aaa bbb ccc ddd #vi file2 111 222 333 aaa (4 Replies)
Discussion started by: ust
4 Replies

10. UNIX for Dummies Questions & Answers

find filename based on file content

:confused: There is a flat file on my system which contains email addreses of people in my company. This file is utilized when sending notifications for various things. However nobody knows where this file is located or what it is named. The only thing we know is the email address of a user who... (4 Replies)
Discussion started by: kollerj
4 Replies
Login or Register to Ask a Question