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
# 8  
Old 02-17-2009
@Whiteboard

he write:

"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"
# 9  
Old 02-17-2009
oops... sorry.. then the solution given by you and vgersh99 will work fine...

Code:
 
nawk 'FNR==NR {a[$0]++; next} a[$0]' xxx.txt yyy.txt

# 10  
Old 02-17-2009
Code:
 
nawk 'FNR==NR {a[$0]++; next} a[$0]' xxx.txt yyy.txt

@vgersh99

Can you pls explain ur code....
# 11  
Old 02-17-2009
Quote:
Originally Posted by kaixinsjtu
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.
use 'awk' instead of 'nawk'.
# 12  
Old 04-01-2009
nawk - dummie question

Iīm tried do something very similar
list A
1
List B
1 2 3
And want list C with intersection of A and B by column 1
with
1 2 3
as answer

I tried
B=ListOfProcess=$(ps -ef | grep sappp | awk '{print $1,$2,$6}' | perl -lne 'print unless /root/ | /user1/ | /user2/ | /user3/ | /user4/' | sort)


A=ListToKill= $(who -u | sort +5 |awk '{print $1,$6,$2}' | perl -lne 'print unless /root/ | /user1/ | /user2/ | /user3/ | /user4/ | /0:/' |awk '{print $3}' |sort)

awk 'FNR==NR {a[$0]++; next} !a[$0]' A B

But didīt work, its giving the total instead the intersection only.

A link for other topic is enough, I can try understand other examples just didnt find yet.
Thanks
 
Login or Register to Ask a Question

Previous Thread | Next Thread

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. Shell Programming and Scripting

Script to find NOT common strings in two files

Hi all, I'd like you to help or give any advise about the following: I have two (2) files, file1 and file2, both files have information common to each other. The contents of file1 is a subset of the contents of file2: file1: errormsgadmin esdp esgservices esignipa iprice ipvpn irm... (0 Replies)
Discussion started by: hnux
0 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
Login or Register to Ask a Question