The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
ksh pattern matching ripat Shell Programming and Scripting 5 02-10-2008 04:44 PM
help need for pattern matching HIMANI UNIX for Dummies Questions & Answers 10 01-22-2008 07:30 AM
Pattern Matching op4_u Shell Programming and Scripting 10 07-18-2006 01:30 AM
grep - to exclude lines beginning with pattern frustrated1 Shell Programming and Scripting 2 08-29-2005 08:18 AM
Pattern matching sed leemjesse Shell Programming and Scripting 3 03-23-2005 04:06 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-28-2008
greptastic greptastic is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 14
exclude columns with a matching line pattern

Hi ,

I have 5 columns total and am wanting to search lines in columns 3-5 and basically grep -v patterns that match 'BBB_0123' 'BVG_0895' 'BSD_0987'

Does anyone know how to do this? I tried combining grep -v with grep -e but, it didn't work.

Thanks!
  #2 (permalink)  
Old 06-29-2008
robotronic's Avatar
robotronic robotronic is offline Forum Advisor  
Can I play with madness?
  
 

Join Date: Apr 2002
Location: Italy
Posts: 370
Given an input file like this:


Code:
test ~ $ cat example.txt
aaaaaaaa bbbbbbbb BBB_0123 dddddddd eeeeeeee
ffffffff gggggggg hhhhhhhh iiiiiiii jjjjjjjj
kkkkkkkk llllllll mmmmmmmm nnnnnnnn BVG_0895
pppppppp qqqqqqqq rrrrrrrr ssssssss tttttttt
uuuuuuuu vvvvvvvv BSD_0987 xxxxxxxx BBB_0123
zzzzzzzz BVG_0895 22222222 33333333 44444444
BSD_0987 66666666 77777777 88888888 99999999

Try:

Code:
awk '$3 !~ /BBB_0123|BVG_0895|BSD_0987/ && $5 !~ /BBB_0123|BVG_0895|BSD_0987/' example.txt

The output will be:

Code:
ffffffff gggggggg hhhhhhhh iiiiiiii jjjjjjjj
pppppppp qqqqqqqq rrrrrrrr ssssssss tttttttt
zzzzzzzz BVG_0895 22222222 33333333 44444444
BSD_0987 66666666 77777777 88888888 99999999

  #3 (permalink)  
Old 06-29-2008
greptastic greptastic is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 14
Still need a little more help....

I think I should explain a little more...
I want to exclude cases where there is information in all three columns (ie. BBB_0123 BVG_0895 BSD_0987 straight across) and only keep lines that have gaps :
Thanks so much for your help!

BBB_0123 BVG_0895 BSD_0987
BBB_0123 BVG_0895 BSD_0987
BBB_0123 BSD_0987
BBB_0123 BVG_0895
BVG_0895
BBB_0123 BVG_0895 BSD_0987
  #4 (permalink)  
Old 06-29-2008
greptastic greptastic is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 14
Still need more help....

I think I should explain a little more...
I want to exclude cases where there is information in all three columns (ie. BBB_0123 BVG_0895 BSD_0987 straight across) and only keep lines that have gaps :
Thanks so much for your help!

BBB_0123 BVG_0895 BSD_0987
BBB_0123 BVG_0895 BSD_0987
BBB_0123 BSD_0987
BBB_0123 BVG_0895
BVG_0895
BBB_0123 BVG_0895 BSD_0987
  #5 (permalink)  
Old 06-29-2008
reborg's Avatar
reborg reborg is offline Forum Staff  
Administrator
  
 

Join Date: Mar 2005
Location: Ireland
Posts: 4,245
Please do not post a new thread to bump up and existing one.

Threads merged.
  #6 (permalink)  
Old 06-30-2008
robotronic's Avatar
robotronic robotronic is offline Forum Advisor  
Can I play with madness?
  
 

Join Date: Apr 2002
Location: Italy
Posts: 370
I still don't understand, where are the five columns you talked about?

Could you please provide a real input file and the expected output?

If the input file is identical to the one you posted, you simply need:

Code:
grep -v "BBB_0123 BVG_0895 BSD_0987" input_file.txt

If you want to remove all the lines containing ALL three occurrences of the patterns, regardless of the patterns' order in the line, you may try this:

Code:
awk '{
   split("", x);
   for (i=1;i<=NF;i++) x[$i]++;
   if (!(x["BBB_0123"] && x["BVG_0895"] && x["BSD_0987"])) print;
}' input_file.txt

Use nawk if you're on Solaris OS.

Last edited by robotronic; 06-30-2008 at 06:57 AM..
Closed Thread

Bookmarks

Tags
solaris

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting 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




All times are GMT -4. The time now is 05:39 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0