lines
lines

Reputation: 25

grep exclude strings somthing with regular expression string

I had a test file:

base64_decode(xxx)
bas'.'e64'.'_decode(xxx)
ba'.'s'.'e64'.'_deco'.'de(xxx)
xxxxxxx
ttttttt
bbbbbb
vvvvvvv
b'.'a'.'s'.'e'.'64'.'_de'.'co'.'de(xxx)

I had the test command

grep -i -E -e "b[\'\.]*a[\'\.]*s[\'\.]*e[\'\.]*6[\'\.]*4[\'\.]*_[\'\.]*d[\'\.]*e[\'\.]*c[\'\.]*o[\'\.]*d[\'\.]*e[\'\.]*" test.txt

But,the result included the line

base64_decode(xxx)

I want remove this line:

base64_decode(xxx)

and must include this lines:

bas'.'e64'.'_decode(xxx)
ba'.'s'.'e64'.'_deco'.'de(xxx)
b'.'a'.'s'.'e'.'64'.'_de'.'co'.'de(xxx)

I think my regular expression string is wrong.

So help me please, thanks~~~

Upvotes: 0

Views: 126

Answers (3)

shrug
shrug

Reputation: 47

I don't know grep, so I'm not sure if this regex will work as it requires support for positive lookahead. But here it is:

^b(?=[ase64_dcod]*')[.']*a[.']*s[.']*e[.']*6[.']*4[.']*_[.']*d[.']*e[.']*c[.']*o[.']*d[.']*e[.']*.+$

Basically checks to see if there is a single quote somewhere after the initial 'b' before matching the rest of the string.

If supported, possessive modifiers (+) after the *'s might speed up searches.

https://regex101.com/r/UiCyCN/2

Upvotes: 0

Cyrus
Cyrus

Reputation: 88601

grep "'" file

Output:

bas'.'e64'.'_decode(xxx)
ba'.'s'.'e64'.'_deco'.'de(xxx)
b'.'a'.'s'.'e'.'64'.'_de'.'co'.'de(xxx)

Upvotes: 1

Steephen
Steephen

Reputation: 15824

Didn't you try this ?

cat <file> | grep -v  base64

Or as commented by Bohemian

grep -v base64 <file>

Upvotes: 0

Related Questions