Regex to match when input is not a certain string (can't use grep -v)


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Regex to match when input is not a certain string (can't use grep -v)
# 1  
Old 02-03-2010
Regex to match when input is not a certain string (can't use grep -v)

Hey everyone,

Basically, all I'm looking for is a way to regex for not a certain string. The regex I'm looking to avoid matching is:

Code:
D[A-Z]222

i.e. an equivalent of:

Code:
awk '!/D[A-Z]222/'

The problem is that I use this in the following command in a Bash script:

Code:
ls ${source_directory} | awk '/${mutant}/ && /short.*\.prmtop/'

Where ${mutant} is the regex, I'm interested in. It gets this from a series of directories named things like:

Code:
DG222
DE222
WT
DN222

The problem is that in the source directory, the filenames to go in WT/ are only distinguishable by the lack of this D[A-Z]222 in the name. I didn't want to include the enclosing /s around the regex into ${mutant} (and append a ! to the front) because I was worried about escaping /s properly in Bash.

Cheers,

Kyle
# 2  
Old 02-03-2010
Code:
cd ${source_directory}
ls  | awk '/"'"${mutant}"'"/ && /short.*\.prmtop/'

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep string with regex numeric characters

Hi all, I have the following entries in a file: Cause Indicators=80 90 Cause Indicators=80 90 Cause Indicators=82 90 Cause Indicators=82 90 Cause Indicators=82 90 The first 2 digits might change so I am after a sort of grep which could find any first 2 digits + the second 2,... (3 Replies)
Discussion started by: nms
3 Replies

2. Shell Programming and Scripting

Grep with regex containing one string but not the other

Hi to you all, I'm just struggling with a regex problem and I'm pretty sure that I'm missing sth obvious... :confused: I need a regex to feed my grep in order to find lines that contain one string but not the other. Here's the data example: 2015-04-08 19:04:55,926|xxxxxxxxxx| ... (11 Replies)
Discussion started by: stresing
11 Replies

3. Shell Programming and Scripting

Read input and match string

#!/bin/ksh echo DB LIST ps -ef | grep pmon | grep -v grep | awk -F_ '{print $3}' | sort db_up=`ps -ef | grep pmon | grep -v grep | awk -F_ '{print $3}' | sort` echo echo "Enter database name from the above list" echo read ORACLE_SID echo echo Database selected is: $ORACLE_SID echo ... (10 Replies)
Discussion started by: crazy_max
10 Replies

4. Shell Programming and Scripting

Regex to match only first occurence with grep

Hello to all, How would be the correct regex to match only the first occurence of the pattern 3.*6. I'm trying with 3.*6 trying to match only 34rrte56, but with my current regex is matching 4rrte567890123456789123powiluur56. And if I try with ? doesn't print anything echo... (6 Replies)
Discussion started by: Ophiuchus
6 Replies

5. Shell Programming and Scripting

Print lines that match regex on xth string

Hello, I need an awk command to print only the lines that match regex on xth field from file. For example if I use this command awk -F"|" ' $22 == "20130117090000.*" 'It wont work, I think, because single quotes wont allow the usage of the metacharacter star * . On the other hand I dont know... (2 Replies)
Discussion started by: black_fender
2 Replies

6. Shell Programming and Scripting

perl regex string match issue..kindly help

i have a script in which i need to skip comments, and i am able to achieve it partially... IN text file: {**************************** {test : test...test } Script: while (<$fh>) { push ( @data, $_); } if ( $data =~ m/(^{\*+$)/ ){ } With the above match i am... (5 Replies)
Discussion started by: avskrm
5 Replies

7. Shell Programming and Scripting

Match string from two file input

Hello all, I have file like this: file 1: aa bb cc dd ee file2: 111 111 111 111 111 111 (2 Replies)
Discussion started by: attila
2 Replies

8. Shell Programming and Scripting

Grep a string from input file and delete next three lines including the line contains string in xml

Hi, 1_strings file contains $ cat 1_strings /home/$USER/Src /home/Valid /home/Review$ cat myxml <projected value="some string" path="/home/$USER/Src"> <input 1/> <estimate value/> <somestring/> </projected> <few more lines > <projected value="some string" path="/home/$USER/check">... (4 Replies)
Discussion started by: greet_sed
4 Replies

9. Shell Programming and Scripting

grep regex, match exact string which includes "/" anywhere on line.

I have a file that contains the 2 following lines (from /proc/mounts) /dev/sdc1 /mnt/backup2 xfs rw,relatime,attr2,noquota 0 0 /dev/sdb1 /mnt/backup xfs rw,relatime,attr2,noquota 0 0 I need to match the string in the second column exactly so that only one result is returned, e.g. > grep... (2 Replies)
Discussion started by: jelloir
2 Replies

10. Shell Programming and Scripting

grep fixed string with regex

Hello, all! Maybe the title is badly formulated, you can help me with that...! I'm using the GNU grep, and I need to make sure that grep will extract only what I tell it to. I have the following regular expression: *? Well, I need to make sure I grep only a word which may start with a... (11 Replies)
Discussion started by: teresaejunior
11 Replies
Login or Register to Ask a Question