Help removing multiple lines from one file with a list from a second file!


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Help removing multiple lines from one file with a list from a second file!
# 1  
Old 08-27-2011
Help removing multiple lines from one file with a list from a second file!

I am trying to remove the lines listed in example File A from File B to achieve File C. Both files are much larger than the examples below. (File B has up to 6,000 lines).

I have searched the forums and I have not been able to find an answer to this particular question.

I tried
Code:
grep -v -f fileA.txt fileB.txt > fileC.txt

but this removed everything in File B that had any of the numbers listed in File A (for example it also deleted rows 30,35,65, etc...)

File examples:

File A
Code:
0
3
5
6

File B
Code:
0    NC426766GEIY5UL03G3PB7    R342835GEIY5UL03GIOFU
1    K4109290GEIY5UL03GL9L3    NC199950GEIY5UL03FNGVL
2    K474585GEIY5UL03FTK58
3    PK19586GEIY5UL03GX5R1
4    K45478GEIY5UL03GRH9T    K113069GEIY5UL03G4OER    
5    NP171487GEIY5UL03GQZW3
6    NPK471900GEIY5UL03GPTWF    NPK483497GEIY5UL03GM934    
7    P267607GEIY5UL03FOGRW
8    B41873GEIY5UL03HBFP8    B411015GEIY5UL03G1UGF
9    N2108841GEIY5UL03HEJH7
10    P491173GEIY5UL03HJHQ4

Ideally, File C would have rows 0,3,5 and 6 removed and look like this:

Code:
1    K4109290GEIY5UL03GL9L3    NP199950GEIY5UL03FNGVL
2    K474585GEIY5UL03FTK58
4    K45478GEIY5UL03GRH9T    K113069GEIY5UL03G4OER    
7    P267607GEIY5UL03FOGRW
8    C41873GEIY5UL03HBFP8    C411015GEIY5UL03G1UGF
9    N2108841GEIY5UL03HEJH7
10    P491173GEIY5UL03HJHQ4

Thanks so much for any help!

Last edited by Franklin52; 08-28-2011 at 09:28 AM.. Reason: Please use code tags for data and code samples, thank you
# 2  
Old 08-27-2011
Perhaps, try with -w option
Code:
grep -v -w -f fileA.txt fileB.txt > fileC.txt

This User Gave Thanks to dude2cool For This Post:
# 3  
Old 08-27-2011
Thank you! That worked!!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Removing lines from a file

I have a file `/tmp/wrk` containing filenames with paths. I want to remove filenames from this file, for example remove all filenames containing alja cagr cavt clta cmdo or corl remove all filenames containing data for days in region `d.2016.001` to `d.2016.207` remove all filenames... (10 Replies)
Discussion started by: kristinu
10 Replies

2. Shell Programming and Scripting

Removing carriage returns from multiple lines in multiple files of different number of columns

Hello Gurus, I have a multiple pipe separated files which have records going over multiple Lines. End of line separator is \n and records going over multiple lines have <CR> as separator. below is example from one file. 1|ABC DEF|100|10 2|PQ RS T|200|20 3| UVWXYZ|300|30 4| GHIJKL|400|40... (7 Replies)
Discussion started by: dJHa
7 Replies

3. Shell Programming and Scripting

Removing multiple lines from input file, if multiple lines match a pattern.

GM, I have an issue at work, which requires a simple solution. But, after multiple attempts, I have not been able to hit on the code needed. I am assuming that sed, awk or even perl could do what I need. I have an application that adds extra blank page feeds, for multiple reports, when... (7 Replies)
Discussion started by: jxfish2
7 Replies

4. Shell Programming and Scripting

Removing lines from a file

Hi, I have a linux server that was hacked and I have a bunch of files that sporadically contain the following lines through out the file: <?php eval(base64_decode("Xxxxxxxxxxxxxx/xxxxxxxx")); I did't put the exact lines of the file in this post. The "Xxxx" are random letters/numbers.... (8 Replies)
Discussion started by: nck
8 Replies

5. UNIX for Dummies Questions & Answers

print multiple lines from text file based on pattern list

I have a text file with a list of items/patterns: ConsensusfromCGX_alldays_trimmedcollapsedfilteredreadscontiglist(229095contigs)contig12238 ConsensusfromCGX_alldays_trimmedcollapsedfilteredreadscontiglist(229095contigs)contig34624... (1 Reply)
Discussion started by: Oyster
1 Replies

6. UNIX for Dummies Questions & Answers

removing multiple lines of text in a file

Hi, I'm trying to remove multiple lines of text based off a series of different words and output it to a new file The document contains a ton of data but i want to delete any line that has the following mx1.rr.biz.com or ns2.ri.biz.com i tried using grep -v filename "mx1.rr.biz.com" >... (3 Replies)
Discussion started by: spartan22
3 Replies

7. Shell Programming and Scripting

Removing the first and last lines in a file

Hi Gurus, I'm a little new to UNIX. How can I do remove the first and last line in a file? Say, supppose I have a file as below: Code: 1DMA 400002BARRIE 401002CALGARY/LETHBRI 402002CARLETON 500001PORTLAND-AUBRN 501001NEW YORK, NY 502001BINGHAMTON, NY ... (2 Replies)
Discussion started by: naveendronavall
2 Replies

8. AIX

Removing the first and last lines in a file

Hi Gurus, I'm a little new to UNIX. How can I do remove the first and last line in a file? Say, supppose I have a file as below: 1DMA 400002BARRIE 401002CALGARY/LETHBRI 402002CARLETON 500001PORTLAND-AUBRN 501001NEW YORK, NY ... (1 Reply)
Discussion started by: naveendronavall
1 Replies

9. UNIX for Dummies Questions & Answers

Removing lines from a file

I'm trying to find a command which will allow me to remove a range of lines (2-4) from a .dat file from the command line without opening the file. Someone mentioned using the ex command? Does anyone have any ideas? thanks (6 Replies)
Discussion started by: computersaysno
6 Replies

10. Shell Programming and Scripting

Removing lines from a file

Hello i have 2 files file1 and file2 as shown below file1 110010000000206|567810008161509 110010000000207|567810072227627 110010000000208|567811368851555 110010000000209|567811422513652 110010000000210|567812130217683 110010000000211|567813220211182 110010000000212|567813449322589... (4 Replies)
Discussion started by: PradeepRed
4 Replies
Login or Register to Ask a Question