Remove lines in file1 with values from file2


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Remove lines in file1 with values from file2
# 1  
Old 01-22-2012
Remove lines in file1 with values from file2

Hello,
I have two data files:

file1
Code:
12345 aa bbb cccc
98765 qq www uuuu
76543 pp rrr bbbbb
34567 nn ccc sssss
87654 qq ppp rrrrr

file2
Code:
98765
34567

I need to remove the lines from file1 if the first field contains a value that appears in file2:

output
Code:
12345 aa bbb cccc
76543 pp rrr bib
87654 qq ppp rrrrr

Thanks so much!

Moderator's Comments:
Mod Comment Please use [CODE][/CODE] tags where appropriate, thank you

Last edited by vbe; 01-22-2012 at 04:58 AM..
# 2  
Old 01-22-2012
Checkout the below thread. I too had a same requirement.

https://www.unix.com/shell-programmin...ther-file.html
This User Gave Thanks to machomaddy For This Post:
# 3  
Old 01-22-2012
Perfect, thanks!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Mapping the values of ids of two columns of file1 from file2

I have of two space separated files: ==> File1 <== PT|np_496075.1 st|K92748.1 st|K89648.1 PT|np_001300561.1 PT|np_497284.1 st|K90752.1 st|K90279.1 PT|np_740775.1 PT|np_497749.1 st|K90752.1 st|K92038.1 PT|np_490856.1 PT|np_497284.1 st|K90752.1 st|K88095.1 PT|np_494764.1 ==> File 2 <==... (2 Replies)
Discussion started by: sammy777888
2 Replies

2. UNIX for Dummies Questions & Answers

Compare file1 and file2, print matching lines in same order as file1

I want to print only the lines in file2 that match file1, in the same order as they appear in file 1 file1 file2 desired output: I'm getting the lines to match awk 'FNR==NR {a++}; FNR!=NR && a' file1 file2 but they are in sorted order, which is not what I want: Can anyone... (4 Replies)
Discussion started by: pathunkathunk
4 Replies

3. Shell Programming and Scripting

Remove rows from file2 if it exists in file1

I have 2 file, file1 and file2. file1 has some keys and file2 has keys+some other data. I want to remove the lines from file2,if the key for that line exists in file1. file1: key1 key2 flie2: key1,moredata key2,moredata key3,moredata Required output: key3,moredata Thanks EDIT:... (6 Replies)
Discussion started by: chacko193
6 Replies

4. UNIX for Dummies Questions & Answers

if matching strings in file1 and file2, add column from file1 to file2

I have very limited coding skills but I'm wondering if someone could help me with this. There are many threads about matching strings in two files, but I have no idea how to add a column from one file to another based on a matching string. I'm looking to match column1 in file1 to the number... (3 Replies)
Discussion started by: pathunkathunk
3 Replies

5. Shell Programming and Scripting

Remove words from file2 that don't exist in file1

Hi I have to list of words file1 and file2, I want to compare both lists and remove from file2 all the words that don't exist in file1. How can I do this? Many thanks (4 Replies)
Discussion started by: noliveira
4 Replies

6. Shell Programming and Scripting

Get values from different columns from file2 when match values of file1

Hi everyone, I have file1 and file2 comma separated both. file1 is: Header1,Header2,Header3,Header4,Header5,Header6,Header7,Header8,Header9,Header10 Code7,,,,,,,,, Code5,,,,,,,,, Code3,,,,,,,,, Code9,,,,,,,,, Code2,,,,,,,,,file2... (17 Replies)
Discussion started by: cgkmal
17 Replies

7. Shell Programming and Scripting

Display lines from file1 that are not in file2

Hi there, I know the command diff but what I want is slightly different. I have two files containing lines that look like md5sums. file1 5a1e8cee2eb2157c86e7266ee38e47c3 /tmp/file1 a254c48bdd064a40b82477b9fa5be05d /tmp/file2 2d57c72ec898acddf8a6bacb3f821572 /tmp/file3... (5 Replies)
Discussion started by: chebarbudo
5 Replies

8. Shell Programming and Scripting

AWK: read values from file1; search for values in file2

I have read another post about this issue and am wondering how to adapt it to my own, much simpler, issue. I have a file of user IDs like so: 333333 321321 546465 ...etc I need to take each number and use it to print records wherein the 5th field matches the user ID pulled from the... (2 Replies)
Discussion started by: Bubnoff
2 Replies

9. Shell Programming and Scripting

Search values between ranges in File1 within File2

Hi people, I have 2 files, one with a list of non consecutive ranges (File1.txt), where each range begins with the value in column 1 and finishes with the value in column 2 in the same line, as can be seen above. 215312581156279 215312581166279 215312582342558 215312582357758... (4 Replies)
Discussion started by: cgkmal
4 Replies

10. Shell Programming and Scripting

delete lines from file2 beginning w/file1

I've been searching around here and other places, but can't put this together... I've got a unique list of words in file 1 (one word on each line). I need to delete each line in file2 that begins with the word in file1. I started this way, but want to know how to use file1 words instead... (13 Replies)
Discussion started by: michieka
13 Replies
Login or Register to Ask a Question