exclude columns with a matching line pattern


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers exclude columns with a matching line pattern
# 1  
Old 06-28-2008
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  
Old 06-29-2008
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  
Old 06-29-2008
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  
Old 06-29-2008
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  
Old 06-29-2008
Please do not post a new thread to bump up and existing one.

Threads merged.
# 6  
Old 06-30-2008
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..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How do I select certain columns with matching pattern and rest of the lines?

I want to select 2nd, 3rd columns if line has "key3" and print rest of the lines as is. # This is my sample input key1="val1" key2="val2" key3="val3" key4="val4" some text some text some text some text key1="val1" key2="val2" key3="val3" key4="val4" some text some text some text some... (3 Replies)
Discussion started by: kchinnam
3 Replies

2. UNIX for Dummies Questions & Answers

Print only the duplicate line only with matching columns

Hi There, I have an I/P which looks like -- 1 2 3 4 5 1 2 3 4 6 4 7 8 9 9 5 6 7 8 9 I would like O/P to be --- 1 2 3 4 5 1 2 3 4 6 So, printing only the consecutive lines where $1,$2,$3,$4 are matching. Is there any command to do this or small awk script? Thanks, (12 Replies)
Discussion started by: Indra2011
12 Replies

3. Shell Programming and Scripting

Fetching a line matching a pattern

Hi Gurus, I have a file as follows (Sample shown below but the list is very huge) SCHEDULE WS1#JS1 RUNCYCLE1 : WS1#JOB1 WS1#JOB2 FOLLOWS JOB1 END SCHEDULE WS2#JS1 RUNCYCLE2 : WS1#JOB3 WS1#JOB1 FOLLOWS JOB3 WS2#JOB1 (10 Replies)
Discussion started by: jayadanabalan
10 Replies

4. Shell Programming and Scripting

Sed: printing lines AFTER pattern matching EXCLUDING the line containing the pattern

'Hi I'm using the following code to extract the lines(and redirect them to a txt file) after the pattern match. But the output is inclusive of the line with pattern match. Which option is to be used to exclude the line containing the pattern? sed -n '/Conn.*User/,$p' > consumers.txt (11 Replies)
Discussion started by: essem
11 Replies

5. Shell Programming and Scripting

awk to copy previous line matching a particular columns

Hello Help, 2356798 7689867 999 000 123678 20385907 9797 666 17978975 87468976 968978 98798 I am trying to have out put which actually look for the third column value of 9797 and then it insert line there after with first, second column value exactly as the previous line and replace the third... (3 Replies)
Discussion started by: Indra2011
3 Replies

6. Shell Programming and Scripting

Duplicate line removal matching some columns only

I'm looking to remove duplicate rows from a CSV file with a twist. The first row is a header. There are 31 columns. I want to remove duplicates when the first 29 rows are identical ignoring row 30 and 31 BUT the duplicate that is kept should have the shortest total character length in rows 30... (6 Replies)
Discussion started by: Michael Stora
6 Replies

7. Shell Programming and Scripting

matching pattern to end of line

I have the following code and want to get only the comments. Ideally I would like to replace the characters to the left of the first '!' in the line with blanks. real, dimension(:), allocatable :: ft ! stores a single trace real, dimension(:), allocatable :: tr ! stores a single... (8 Replies)
Discussion started by: kristinu
8 Replies

8. Shell Programming and Scripting

How to use sed to modify a line above or below matching pattern?

I couldn't figure out how to use sed or any other shell to do the following. Can anyone help? Thanks. If seeing a string (e.g., TODAY) in the line, replace a string in the line above (e.g, replace "Raining" with "Sunny") and replace a string in the line below (e.g., replace "Reading" with... (7 Replies)
Discussion started by: sprinner
7 Replies

9. Shell Programming and Scripting

using command line arguments as columns for pattern matching using awk

Hi, I wish to use a column, as inputted by a user from command line, for pattern matching. awk file: { if($1 ~ /^8/) { print $0> "temp2.csv" } } something like this, but i want '$1' to be any column as selected by the user from command line. ... (1 Reply)
Discussion started by: invinclible0009
1 Replies

10. Shell Programming and Scripting

comment/delete a particular pattern starting from second line of the matching pattern

Hi, I have file 1.txt with following entries as shown: 0152364|134444|10.20.30.40|015236433 0233654|122555|10.20.30.50|023365433 ** ** ** In file 2.txt I have the following entries as shown: 0152364|134444|10.20.30.40|015236433 0233654|122555|10.20.30.50|023365433... (4 Replies)
Discussion started by: imas
4 Replies
Login or Register to Ask a Question