Quote:
Originally Posted by pixellany
I thought homework also, but the posting history says maybe not.
If it is homework, how about a trick question? My favorite--in chemistry class: What is this compound? BaNa2 (subscript 2)
|
Believe that I've read man pages but parentheses and angle brackets are tricky characters
There is no tricks or homework. The only trick here is that It's my fault for I haven't documented my own scripts that has the function that I use for parsing radius logs:
Code:
Incorrect(){
#I don't want to match with some other kind of Incorrect Access
awk '$9 ~ /incorrect/ && $10 ~ /([^[(<]])/ { print tolower($10) }'
}
Really parentheses are not needed here. So we have:
[^[(<]]
So this match on whatever be on 10th field that has parentheses or angle brackets...
I prevent so that entries like:
[<no
(rlm_ldap:
are included int the output
I was confused because I was playing with:
Code:
awk '$9 ~ /incorrect/ && $10 ~ /([[(<]])/ { print tolower($10) }' logfile
and it outputs nothing, but even so the expression above works fine,
So I've just remembered and I am documenting what I wanted to do
:
Let's suppose we have a file "q" with:
[<xxxxx ]
(
[saralnadasd]
We want match only '[saralnadasd]'
If I use
Code:
awk '$1 ~ /[^(<]/ {print $1}' q
I get:
[<xxx
(xxxx
[saralnadasd]
that is not what we are looking for.
If I use
Code:
awk '$1 ~ /^[(<]/ {print $1}' q
(xxxx
Of course because "^" out of squared brackets means beginning of the line. That is not we want again
It works if we use:
Code:
awk '$1 ~ /[^[(<]]/ {print $1}' q
[saralnadasd]
I was confused because removing "^" from the regex is not the right way to get the reverse thing (yes, yes I know that I can use "!~ in awk, but was trying to remember what I did), the correct reverse regex is:
Code:
awk '$1 ~ /[(<]/ {print $1}' q
[<xxx
(xxxx
I'd hope that my somewhat confuse explanation be useful to someone