Search a list of lines in file into files


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Search a list of lines in file into files
# 1  
Old 05-20-2008
Search a list of lines in file into files

I have a file (file1) which is like

host1
host2
host3
host4
the list goes on............


Now I want the above lines in files to be compared with files under
/opt/new/

File names are as below:
Dev
Prod
QA

And suppose host1 from file1 is found under Dev(file under /opt/new) than it should write under a seperate file New-list as host1-DEV

Thanks
# 2  
Old 05-20-2008
Code:
while read line; do echo ${line}-$(grep -l $line /opt/new/*); done < buf > new-buf


Last edited by agn; 05-20-2008 at 02:20 AM.. Reason: screwed up code block
# 3  
Old 05-20-2008
Thanks:

Thanks, It worked !
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Search multi lines in to multiple files

how to find multiple lines in to multiple files if matched lines then do f1 f2 f3 are files ,lines contain matched lines f1 asdasdasdasd asdasdasdasd abc def Business date cannot be as of date ghi sdasdasdasda asdasdasdada f2 (1 Reply)
Discussion started by: Kalia
1 Replies

2. UNIX for Dummies Questions & Answers

Search list of files

Hi All, I Have 2 files. file1: abc.xml.gz abcd.xml.gz xyz.xml.gz X.xml.gz File2 abc. x. cde. unix. My requirment is search File1 using File2 and need below ouput. (6 Replies)
Discussion started by: j.vutakanti
6 Replies

3. 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

4. Shell Programming and Scripting

Take a list if strings from a file and search them in a list of files and report them

I have a file 1.txt with the below contents. -----cat 1.txt----- 1234 5678 1256 1234 1247 ------------------- I have 3 more files in a folder -----ls -lrt------- A1.txt A2.txt A3.txt ------------------- The contents of those three files are similar format with different data values... (8 Replies)
Discussion started by: realspirituals
8 Replies

5. UNIX for Dummies Questions & Answers

Search for lines in one file in another

I am trying to search for lines present in file a that do not exist in file b and print out the lines. E.g. file a apple pear banana orange file b apple banana orange would output to stdout: pear. ... (3 Replies)
Discussion started by: thurmc
3 Replies

6. UNIX for Dummies Questions & Answers

script to search patterns inside list of files

>testfile while read x do if then echo $x >> testfile else fi if then echo $x >> testfile else fi done < list_of_files is there any efficient way to search abc.dml and xyz.dml ? (2 Replies)
Discussion started by: dr46014
2 Replies

7. UNIX for Dummies Questions & Answers

Search for different lines in 2 files

Hi guys I need help in comparing 2 files for example file1: asdf|gdddd|acx asdf|vcxzz|eww avxc|bvvce|qwe file2: qwer|asdfg|sss avxc|bvvce|eww aass|weews|llk I need to get the lines that are present in file1 but not found in file2. so in these case (5 Replies)
Discussion started by: khestoi
5 Replies

8. UNIX for Dummies Questions & Answers

Search a string from list of input files

Hello, I am trying to match a string between line one and line two with in the file. But I dont want to search based on the given filename. Instead I want to search for all available files in the specific directory. Please help me on the above. (2 Replies)
Discussion started by: sivakumarvenkat
2 Replies

9. UNIX for Dummies Questions & Answers

List files that do not match the search pattern

I need to list the files that do not match the search pattern: Example: cat file1 This is how it should work cat file2 This is why I like Unix grep -option? Unix * (or some other command) returns file1 (7 Replies)
Discussion started by: olapxpert
7 Replies

10. IP Networking

List files that do not match the search pattern

I need to list the files that do not match the search pattern: Example: cat file1 This is how it should work cat file2 This is why I like Unix grep -option? Unix * (or some other command) returns file1 (1 Reply)
Discussion started by: olapxpert
1 Replies
Login or Register to Ask a Question