Match all except string(s) in posix extended


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Match all except string(s) in posix extended
# 8  
Old 06-02-2011
Quote:
Originally Posted by Chubler_XL
@ygemici
Grep is just used here to demonstrate the extended regular expression in action.
The OP has requested we not use the negation options (! or -v), as these add complexity to the system requiring them.

I can't see any problem with the R.E I supplied; can you supply a string that gives a false positive/negative?
Remember this R.E. is supposed to match any line that doesn't contain "this" or "that".
Ok I already understand but may be many scenarios in our case..

Quote:
Originally Posted by stevensw
With find -regex (with -regextype posix extended) not sed or grep. It is for an auditing script that checks for non-standard filenames.
I guess he wants to determine some rules for user specific conditons to write regex.
But different (sed or awk or grep or perl or ruby or anys (differs in different architectures) ,,can may use different convention as in defined reg libraries..

And according to me , not to use (! or -v) is unobtainable for fixed words
because of this is just significant meaningful for common definitions.So these are already defined for this purpose.

== e.g ==
Code:
# cat audit.log
type=USER_END msg=audit(1304758861.275:29289): user pid=15381 uid=0 auid=0 msg='PAM: session close acct="root" : exe="/usr/sbin/crond" (hostname=?, addr=?, terminal=cron res=success)'

For audit log , I try to write a some regex
[ REGEX= (must be Perl-compatible RegEx) ]
Code:
# REGEX="\w+={1}\w+\s+\w+=\w+\(\d+.\d+:\d+\):\s\w+\s\w+=\d+\s\w+=\d\s\w+=\d\s\w+='\w+:\s+\w+\s\w+\s\w+=\"\w+\"\s+:\s+\w+=\".*\"\s\(\w+=\?,\s\w+=\?,\s\w+=\w+\s\w+=\w+\)'"


Although we dont know will be use which regex library(posix or not or gnu).Just guess..

Now lets look your grep.
for example
Code:
# cat file1
test line is ok!!
test2 line is ok!!!
thissand is ok?
thatcher just way iss OKKs!!
line is that NotOk!!
12 that NotOk!!
that line is notOK
what isthat?
what isthis?
this!!! ok??
that    there is a tab
this is a test
that is a test
this12 is a test
atthis Ok!!
atthat is OK!!
cthats s not OK!!
isthisisokkk
isthatsisokkk


And some lines are missing and some lines has in..
Code:
# grep -E '^([^t]|t[^h]|th[^ia]|thi[^s]|tha[^t])*.{0,3}$' file1
test line is ok!!
test2 line is ok!!!
atthis Ok!!
atthat is OK!!


below is desired output ? I dont think so..
Code:
# grep -Ev "this|that" file1
test line is ok!!
test2 line is ok!!!


now try to grep with wordregexp only supplies containing matches with non_words (not punct)
Code:
# grep -Ewv "this|that" file1
test line is ok!!
test2 line is ok!!!
thissand is ok?
thatcher just way iss OKKs!!
what isthat?
what isthis?
this12 is a test
atthis Ok!!
atthat is OK!!
cthats s not OK!!
isthisisokkk
isthatsisokkk


Try justdoit code (according to me the correct result)
Code:
# ./justdoit2 "this" "that" file1 (this supplies just inverts matches with "this" and "that")
test line is ok!!
test2 line is ok!!!
thissand is ok?
thatcher just way iss OKKs!!
what isthat?
what isthis?
this!!! ok??
this12 is a test
atthis Ok!!
atthat is OK!!
cthats s not OK!!
isthisisokkk
isthatsisokkk


and maybe we get same with this (equals to justdoit)
I modified your --extended-regexp
Code:
# grep -E '^([^t]|t[^h]|th[^ia]|thi[^s]|tha[^t]|that[^ '$'\t]|this[^ '$'\t])*.{0,3}$' file1
test line is ok!!
test2 line is ok!!!
thissand is ok?
thatcher just way iss OKKs!!
what isthat?
what isthis?
this!!! ok??
this12 is a test
atthis Ok!!
atthat is OK!!
cthats s not OK!!
isthisisokkk
isthatsisokkk

regards
ygemici

Last edited by ygemici; 06-02-2011 at 10:44 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Match exactly a string

I am formatting my code and for that I am trying to write a script which can quicken some repetitive work. I need to match "==" exactly in a string and replace it by inserting a (single) blank space before and after it. Sample Strings: 1.this.something =='something'.that... (9 Replies)
Discussion started by: prohank
9 Replies

2. Shell Programming and Scripting

Get the exact match of the string!

Hi All, I am breaking my head in trying to get a command that will exactly match my given string. I have searched net and found few of the options - grep -F $string file grep -x $string file grep "^${string}$" file awk '/"${string}"/ {print $0}' file strangely nothing seems to... (3 Replies)
Discussion started by: dips_ag
3 Replies

3. Shell Programming and Scripting

awk : match the string and string with the quotes :

Hi all, Here is the data file: - want to match only lan3 in the output . - not lan3:1 file : OPERATING_SYSTEM=HP-UX LOOPBACK_ADDRESS=127.0.0.1 INTERFACE_NAME="lan3" IP_ADDRESS="10.53.52.241" SUBNET_MASK="255.255.255.192" BROADCAST_ADDRESS="" INTERFACE_STATE=""... (2 Replies)
Discussion started by: rveri
2 Replies

4. Shell Programming and Scripting

Match a string but with little difference

I want to output the records matched with a string like "abcdefg", but with one letter difference at any position. Can I do this with awk or grep? Thank you! (1 Reply)
Discussion started by: xshang
1 Replies

5. Shell Programming and Scripting

How can I match the particular character in the string?

Hi, I want to check out a word in the text file and generate a clear report for me to see... The text file content: Content: ............ 20120608: 20120608: ............ 20120608: .......... 2012031201: , hime] End of the file My expected output is: Full TXT: manatsu TXT:... (3 Replies)
Discussion started by: meroko
3 Replies

6. UNIX for Dummies Questions & Answers

How to match 2 columns where one column has data as a range - extended

Dear all, there is a nice solution for a text merge where the second file has only variables with a numeric range ( sorry, cannot post URL + thread is closed ). The real world is however more complicated than in the earlier example. file1 A 1 A 2 A 3 B 1 B 2 B 3 B 4 C 1 C 2 C 3 C... (4 Replies)
Discussion started by: underscore
4 Replies

7. UNIX for Dummies Questions & Answers

How do mask off the string that match my value?

Hi, I have a file like following, aaabb aaavv bbdddaaab fgdgjhaa bfd 12352aa dgs1xaf sdgsdyg4 How can i get the output below(mask off all the line that have "a") by using vim #aaabb #aaavv #bbdddaaab #fgdgjhaa bfd #12352aa (4 Replies)
Discussion started by: 793589
4 Replies

8. Shell Programming and Scripting

exact string match ; search and print match

I am trying to match a pattern exactly in a shell script. I have tried two methods awk '/\<mpath${CURR_MP}\>/{print $1 $2}' multipath perl -ne '/\bmpath${CURR_MP}\b/ and print' /var/tmp/multipath Both these methods require that I use the escape character. I am guessing that is why... (8 Replies)
Discussion started by: bash_in_my_head
8 Replies

9. Shell Programming and Scripting

Perl: Better way to match string within a string

Hi, I'm trying to get one field out of many as follows: A string of multiple fields separated with "/" characters: "/ab=12/cd=34/12=ab/34=cd/ef=pick-this.one/gh=blah/ij=something/" I want to pick up the field "ef=pick-this.one" which has no regular pattern except it starts with "ef=xxxx"... (3 Replies)
Discussion started by: Juha
3 Replies

10. UNIX for Dummies Questions & Answers

Posix string to match [[0-999]]

Hi, I would like to set up a Posix string to match the subject line in spam e-mails which contain "" How do I get the square brackets recognised as literals and then include them in a string so that I can reject spam with things like in the subject line. (11 Replies)
Discussion started by: Mair55
11 Replies
Login or Register to Ask a Question