Search words in multiple file line by line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Search words in multiple file line by line
# 1  
Old 03-27-2015
Wrench Search words in multiple file line by line

Hi All

I have to search servers name say like 1000+ "unique names" line by line in child.txt files in another file that is a master file where all server present say "master.txt",if child.txt's server name matches with master files then it print yes else no with server name.
# 2  
Old 03-27-2015
Please show a representative sample of input, desired output, attempts at a solution and specify what OS and versions are being used.
These 2 Users Gave Thanks to Akshay Hegde For This Post:
# 3  
Old 03-27-2015
Thanks for reply,

file child.txt has some 100+ server name written line by line.

like

HTML Code:
SERVERWXM1
SERVERQWE2
SERVERUYT3 ..and so on
And the Master file has all the servers name information more than 300 servers names.So I need to check SERVERWXM1 in the master file and so for 100+ server names ,if these server names is matching with master_files.txt then print yes or else not,both files have line by line entry.
# 4  
Old 03-27-2015
You still didn't post clearly, with some guess try something like this

Code:
awk 'FNR==NR{A[$0];next}{print $0, ($0 in A ? "Yes": "No" )}' master_files.txt child.txt

# 5  
Old 03-27-2015
Print the matching (common) lines:
Code:
fgrep -xf master_files.txt child.txt

Print the non-matching lines (only in child.txt):
Code:
fgrep -vxf master_files.txt child.txt

If the files are sorted you can do the same with
Code:
comm -12 master_files.txt child.txt

and
Code:
comm -13 master_files.txt child.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Number of words in line, while loop, search and grep

Hello, What I wish to attain is: - to read fileA line by line - search entire line as string in fileB - when found, grep the next line in fileB - then merge "searched line" and "found line" in a new file, fileC Here is my fileA: T S Eliot J L Borges L Aragon L L Aragon T S Eliot 4 0... (17 Replies)
Discussion started by: baris35
17 Replies

2. Shell Programming and Scripting

Replace particular words in file based on if finds another words in that line

Hi All, I need one help to replace particular words in file based on if finds another words in that file . i.e. my self is peter@king. i am staying at north sydney. we all are peter@king. How to replace peter to sham if it finds @king in any line of that file. Please help me... (8 Replies)
Discussion started by: Rajib Podder
8 Replies

3. Shell Programming and Scripting

Multiple line search, replace second line, using awk or sed

All, I appreciate any help you can offer here as this is well beyond my grasp of awk/sed... I have an input file similar to: &LOG &LOG Part: "@DB/TC10000021855/--F" &LOG &LOG &LOG Part: "@DB/TC10000021852/--F" &LOG Cloning_Action: RETAIN &LOG Part: "@DB/TCCP000010713/--A" &LOG &LOG... (5 Replies)
Discussion started by: KarmaPoliceT2
5 Replies

4. Shell Programming and Scripting

USING sed to remove multiple strings/words from a line

Hi I use sed comnand to remove occurance of one workd from a line. However I need to removed occurance of dufferent words in ne line. Original-1 Hi this is the END of my begining Comand sed s/"END"/"start"/g Output-1 Hi this is the start of my beginig But I have more... (9 Replies)
Discussion started by: mnassiri
9 Replies

5. Shell Programming and Scripting

Search string within a file and list common words from the line having the search string

Hi, Need your help for this scripting issue I have. I am not really good at this, so seeking your help. I have a file looking similar to this: Hello, i am human and name=ABCD. How are you? Hello, i am human and name=PQRS. I am good. Hello, i am human and name=ABCD. Good bye. Hello, i... (12 Replies)
Discussion started by: royzlife
12 Replies

6. Shell Programming and Scripting

Search words in a line and print next 15 lines.

I have a text file ( basically a log file) and i have 2 words (alpha, beta), Now i want to search these two words in one line and then print next 15 lines in a temp file. there would be many lines with alpha and beta But I need only last occurrence with "alpha" and "beta" and next 15 lines. ... (4 Replies)
Discussion started by: kashif.live
4 Replies

7. Shell Programming and Scripting

PERL or SHELL Scrript to search in Directories by taking line by line from a text file

Unix box server version *********** >uname -r B.11.00 >echo $SHELL /usr/bin/ksh --> in this server, I have the path like /IMbuild/dev/im0serv1 ---> in that directory I have the folders startup(.jsp files nearly 100 jsp's ) and scripts(contains .js files nearly 100 files) ... (9 Replies)
Discussion started by: pasam
9 Replies

8. Shell Programming and Scripting

search a string in a particular column of file and return the line number of the line

Hi All, Can you please guide me to search a string in a particular column of file and return the line number of the line where it was found using awk. As an example : abc.txt 7000,john,2,1,0,1,6 7001,elen,2,2,0,1,7 7002,sami,2,3,0,1,6 7003,mike,1,4,0,2,1 8001,nike,1,5,0,1,8... (3 Replies)
Discussion started by: arunshankar.c
3 Replies

9. UNIX for Dummies Questions & Answers

Searching for multiple words on a line in any order issue

Hi again I have figured out how to be able to sort through lines in a file with multiple words in any order and display them using this command: cat file | grep -i $OPTION1 | grep -i $OPTION2 | grep -i $OPTION3 OPTION1 is 2008, OPTION2 is Mar, OPTION 3 is Tue Result: Tue Mar 25... (4 Replies)
Discussion started by: semaj
4 Replies

10. Shell Programming and Scripting

grep multiple words in a single line

Hi.. How to search for multiple words in a single line using grep?. Eg: Jack and Jill went up the hill Jack and Jill were best friends Humpty and Dumpty were good friends too ---------- I want to extract the 2nd statement(assuming there are several statements with... (11 Replies)
Discussion started by: anduzzi
11 Replies
Login or Register to Ask a Question