trying to grep -v multiple changing sequences from a file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers trying to grep -v multiple changing sequences from a file
# 1  
Old 10-14-2009
trying to grep -v multiple changing sequences from a file

Hello All - I am looking for help on how to solve a re-occuring problem. I have a file with certain sequences in it that need to be removed. The sequences are always different but the fix is always the same remove those sequences and leave the rest. Another team ID's the bad sequences and then I have to remove them. I was using the following command,however, now that I am getting lists of 60 + sequences to remove it doesn't seem like the best way anymore:

grep -v 1234 file | grep -v 5678 | grep -v AAAA | grep -v > newfile

I was trying to write something where I could run the same command or script on the new lists each day but I can't figure it out as my knowledge is limited at best.

Thanks in advance for any help you can give!
# 2  
Old 10-15-2009
You can use the "-f" option on grep, then you only need to generate a file
with the list-pattern.
Example:
Code:
$more list
no
1
3
$more text
line1
no line
the 3 line
the 4 line
$grep -f list -v text 
the 4 line

# 3  
Old 10-15-2009
You might already have your answer, but for my own curosity I'm just trying to understand it as well.

Input: File
Output = Input - lines that contain the specified sequences.
Sequences: You can have any number of sequences each time and each sequence can be of any length?
sequence1 - 1234
sequence2 - 5678
sequence3 - AAAA


Your current code is: n= the number of sequences.
Code:
grep -v sequence1 input file | grep -v sequence2 | grep -v sequence3 | grep -v sequenceN > newfile

So, he would take the sequences that he's given, put them in a file, then run:
Code:
grep -v -f sequence file input file

And to output to a new file just add > newfile at the end of the above grep code? Or would it be | cat >> newfile?
I'm not sure what the above code is that isn't the "$grep -f list -v text" line. What topic is that if I wanted to understand it?

Last edited by MykC; 10-15-2009 at 12:21 PM..
# 4  
Old 10-15-2009
Quote:
Originally Posted by MykC
I'm not sure what the above code is that isn't the "$grep -f list -v text" line. What topic is that if I wanted to understand it?
this code is only and example for using "-f" option whith grep, to make te example i generate one file call list and other call text.
The file list is only a file of patterns and file text is where we want to apply the patterns.
You solution is the same solution that i'm propose.See the code:
Code:
Your code :grep -v -f sequence file input file
My code   :grep -f list -v text

 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need help grep multiple ports in a file.

I wish to grep for an entry in a file if it contains and does not start with #, Listen 443 or Listen 9443 Below is what helped me get Listen 443 but how can I tweak the below command to also include Listen 9443 port ? Note: Listen 8443 or Listen 4438 should fail in the grep. ... (2 Replies)
Discussion started by: mohtashims
2 Replies

2. Shell Programming and Scripting

Getting unique sequences from multiple fasta file

Hi, I have a fasta file with multiple sequences. How can i get only unique sequences from the file. For example my_file.fasta >seq1 TCTCAAAGAAAGCTGTGCTGCATACTGTACAAAACTTTGTCTGGAGAGATGGAGAATCTCATTGACTTTACAGGTGTGGACGGTCTTCAGAGATGGCTCAAGCTAACATTCCCTGACACACCTATAGGGAAAGAGCTAAC >seq2... (3 Replies)
Discussion started by: Ibk
3 Replies

3. Shell Programming and Scripting

Grep multiple keywords from a file

I have a script that will search for a keyword in all the log files. It work just fine. LOG_FILES={ "/Sandbox/logs/*" } for file in ${LOG_FILES}; do grep $1 $file done This only works for 1 keyword. What if I want to search for more then 1 keywords, say 4 or maybe even... (10 Replies)
Discussion started by: Loc
10 Replies

4. Shell Programming and Scripting

Shell script for changing the accession number of DNA sequences in a FASTA file

Hi, I am having a file of dna sequences in fasta format which look like this: >admin_1_45 atatagcaga >admin_1_46 atatagcagaatatatat with many such thousands of sequences in a single file. I want to the replace the accession Id "admin_1_45" similarly in following sequences to... (5 Replies)
Discussion started by: margarita
5 Replies

5. Shell Programming and Scripting

Grep from multiple patterns multiple file multiple output

Hi, I want to grep multiple patterns from multiple files and save to multiple outputs. As of now its outputting all to the same file when I use this command. Input : 108 files to check for 390 patterns to check for. output I need to 108 files with the searched patterns. Xargs -I {} grep... (3 Replies)
Discussion started by: Diya123
3 Replies

6. Shell Programming and Scripting

Grep and replace multiple strings in a file with multiple filenames in a file

Hi, I have a file containing list of strings like i: Pink Yellow Green and I have file having list of file names in a directory j : a b c d Where j contains of a ,b,c,d are as follows a: Pink (3 Replies)
Discussion started by: madabhg
3 Replies

7. UNIX for Dummies Questions & Answers

grep command to find multiple strings in multiple lines in a file.

I want to search files (basically .cc files) in /xx folder and subfolders. Those files (*.cc files) must contain #include "header.h" AND x() function. I am writing it another way to make it clear, I wanna list of *.cc files that have 'header.h' & 'x()'. They must have two strings, header.h... (2 Replies)
Discussion started by: ritikaSharma
2 Replies

8. Shell Programming and Scripting

grep command with changing file name

Hello, I have a grep command as follows: grep Found original_2010.01.26 | cut -f 5 -d ' ' However the file name changes each day and gets appended with today's date. For ex: on January 27th it would be original_2010.01.27 ... etc The files from previous days exist on the... (3 Replies)
Discussion started by: userscript
3 Replies

9. Shell Programming and Scripting

Create Multiple files by reading a input file and changing the contents

Being new to this area .I have been assigned a task which i am unable to do . Can any one please help me . Hi I have requirement where i have input file XYZ_111_999_YYYYMMDD_1.TXT and with header and series of Numbers and Footer. I want to create a mutiple output files with each file having a... (2 Replies)
Discussion started by: bhargavkr
2 Replies
Login or Register to Ask a Question