how to find common words and take them out from two files


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers how to find common words and take them out from two files
# 1  
CPU & Memory how to find common words and take them out from two files

Hi, everyone,
Let's say, we have
xxx.txt
A 1 2 3 4 5
C 1 2 3 4 5
E 1 2 3 4 5

yyy.txt
A 1 2 3 4 5
B 1 2 3 4 5
C 1 2 3 4 5
D 1 2 3 4 5
E 1 2 3 4 5

First I match the first column I find intersection (A,C, E), then I want to take those lines with ACE out from yyy.txt, like
A 1 2 3 4 5
C 1 2 3 4 5
E 1 2 3 4 5

How could I do that??? thanks!!!
# 2  
There're multiple similar threads on these forums - please use the 'Search' function next time
Code:
nawk 'FNR==NR {a[$0]++; next} !a[$0]' xxx.txt yyy.txt

# 3  
There is only gawk here. No nawk. Are they the same??
thanks.

PS: gawk ... doesn't work for me...

Quote:
Originally Posted by vgersh99
There're multiple similar threads on these forums - please use the 'Search' function next time
Code:
nawk 'FNR==NR {a[$0]++; next} !a[$0]' xxx.txt yyy.txt


Last edited by kaixinsjtu; 02-16-2009 at 09:59 PM..
# 4  
Quote:
Originally Posted by kaixinsjtu
There is only gawk here. No nawk. Are they the same??
thanks.

PS: gawk ... doesn't work for me...
What does "does not for me" mean?
Any error messages? Care to quote the output and desired results?
Help us to help you!
# 5  
Ok, I'm a super Rookie.
I put
nawk 'FNR==NR {a[$0]++; next} !a[$0]' xxx.txt yyy.txt
in a txt file call 'awk.txt'
Then I use
> sh awk.txt
awk.txt: line 1: nawk: command not found

I don't know what's wrong.

Quote:
Originally Posted by vgersh99
What does "does not for me" mean?
Any error messages? Care to quote the output and desired results?
Help us to help you!
# 6  
while read VAR;
do
VAR=`echo "$VAR"| cut -d" " -f 1`;
grep "$VAR" yyy.txt;
done < xxx.txt
# 7  
Code:
 
$ cat xxx.txt
A 1 2 3 4 5
C 1 2 3 4 5
E 1 2 3 4 5
 
$ cat yyy.txt
A 1 2 3 4 5
B 1 2 3 4 5
C 1 2 3 4 5
D 1 2 3 4 5
E 1 2 3 4 5
 
 
$ grep -f xxx.txt yyy.txt
A 1 2 3 4 5
C 1 2 3 4 5
E 1 2 3 4 5

 

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?

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find common files between two directories

I have two directories Dir 1 /home/sid/release1 Dir 2 /home/sid/release2 I want to find the common files between the two directories Dir 1 files /home/sid/release1>ls -lrt total 16 -rw-r--r-- 1 sid cool 0 Jun 19 12:53 File123 -rw-r--r-- 1 sid cool 0 Jun 19 12:53... (5 Replies)
Discussion started by: sidnow
5 Replies

2. UNIX for Dummies Questions & Answers

Find a file with common initials and last words

Hi, I have a requirement like i have to find out files and remove them on a daily basis. The files are generated as abc_jnfn_201404230004.csv abc_jnfo_201404230004.csv abc_jnfp_201404230004.csv abc_jnfq_201404230004.csv abd_jnfn_201404220004.csv abe_jnfn_201404220004.csv i want to... (1 Reply)
Discussion started by: Mohammed_Tabish
1 Replies

3. Shell Programming and Scripting

Find common words

Hi, I have 10 files which needs to be print common words from those all files. Is there any command to find out. (2 Replies)
Discussion started by: munna_dude
2 Replies

4. Shell Programming and Scripting

Find Common Values Across Two Files

Hi All, I have two files like below: File1 MYFILE_28012012_1112.txt|4 MYFILE_28012012_1113.txt|51 MYFILE_28012012_1114.txt|57 MYFILE_28012012_1115.txt|57 MYFILE_28012012_1116.txt|57 MYFILE_28012012_1117.txt|57 File2 MYFILE_28012012_1110.txt|57 MYFILE_28012012_1111.txt|57... (2 Replies)
Discussion started by: angshuman
2 Replies

5. Shell Programming and Scripting

Extract common words from two/more csv files

I have two (or more, to make it generic) csv files. Each line contains words separated by comma. None of words have any space. The number of words per line is not fixed. Some may have one, and some may have 12... The number of lines per file is also not fixed. What I need is to find common words... (1 Reply)
Discussion started by: nick2011
1 Replies

6. UNIX for Advanced & Expert Users

Find common Strings in two large files

Hi , I have a text file in the format DB2: DB2: WB: WB: WB: WB: and a second text file of the format Time=00:00:00.473 Time=00:00:00.436 Time=00:00:00.016 Time=00:00:00.027 Time=00:00:00.471 Time=00:00:00.436 the last string in both the text files is of the... (4 Replies)
Discussion started by: kanthrajgowda
4 Replies

7. Shell Programming and Scripting

search of common words in set of files

Hi, I have a set of simple, one columned text files (in thousands). file1: a b c d file 2: b c d e and so on. There is a collection of words in another file: b d b c d e I have to find out the set of words (in each row) is present or absent in the given set of files. So, the... (4 Replies)
Discussion started by: mala
4 Replies

8. Shell Programming and Scripting

Files common in two sets ??? How to find ??

Suppose we have 2 set of files set 1 set 2 ------ ------ abc hgb def ppp mgh vvv nmk sdf hgb ... (1 Reply)
Discussion started by: skyineyes
1 Replies

9. Shell Programming and Scripting

To find all common lines from 'n' no. of files

Hi, I have one situation. I have some 6-7 no. of files in one directory & I have to extract all the lines which exist in all these files. means I need to extract all common lines from all these files & put them in a separate file. Please help. I know it could be done with the help of... (11 Replies)
Discussion started by: The Observer
11 Replies

Featured Tech Videos