Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Mac OS X > simple command line question?

simple command line question?
Thread Tools
Senior User
Join Date: Sep 2000
Location: Shallow Alto, CA
Status: Offline
Reply With Quote
Nov 21, 2003, 12:34 PM
 
Hi,

I would like to scan a large text file (50MB) and remove all lines conating a specific string, lets say "aaaaa". I don't really care about saving those lines, just getting rid of them from the original file.

I tried using the little knowledge of grep that I have, but all I ended up with was a file containing the lines I didn't want.

Any suggestions?

TIA
     
Mac Elite
Join Date: Dec 2001
Location: Atlanta, GA, USA
Status: Offline
Reply With Quote
Nov 21, 2003, 02:46 PM
 
This should work:

Code:
grep -v "pattern" file > output.txt
That will find all lines not containing pattern and will redirect them into the file output.txt
Mac Pro 2x 2.66 GHz Dual core, Apple TV 160GB, two Windows XP PCs
     
foamy  (op)
Senior User
Join Date: Sep 2000
Location: Shallow Alto, CA
Status: Offline
Reply With Quote
Nov 21, 2003, 03:04 PM
 
I found a perl tutorial that gave me some hints and ended up with

perl -pi.bak -e 's/.*G{5,}.*$//; s/.*C{5,}.*$//; s/.*A{5,}.*$//; s/.*T{5,}.*$//; s/^\s*$//' filename

I'm sure there is a more elegant way to do it, but it worked in removing all lines with 5 or more G A T or C.

thanks
     
Senior User
Join Date: Nov 2001
Location: State of Denial
Status: Offline
Reply With Quote
Nov 21, 2003, 03:33 PM
 
DNA?
[Wevah setPostCount:[Wevah postCount] + 1];
     
Senior User
Join Date: Nov 2001
Location: State of Denial
Status: Offline
Reply With Quote
Nov 21, 2003, 03:36 PM
 
Why not just:

perl -pi.bak -e 's/^.*[GCAT]{5,}.*$//;' filename

?
[Wevah setPostCount:[Wevah postCount] + 1];
     
foamy  (op)
Senior User
Join Date: Sep 2000
Location: Shallow Alto, CA
Status: Offline
Reply With Quote
Nov 21, 2003, 03:40 PM
 
Yep DNA.

I spent the last hour trying to get that exact syntax to work, but gave up and just strung them all together one after another.

My knowledge of regular expressions is only as good as the tutorial I'm reading at the time!

Thanks for showing me the elegant way of getting it done...now if I could just get some Linux code to compile I'd be home free.
     
Senior User
Join Date: Nov 2001
Location: State of Denial
Status: Offline
Reply With Quote
Nov 25, 2003, 04:07 AM
 
Word; glad I could be of some help!
[Wevah setPostCount:[Wevah postCount] + 1];
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 02:44 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2