Trouble with a regular expression : [^<>]

Belaran

Registered
Hi !

This is my problem.Normally this regular expression

[^<>]

should suppress any line which do not have "<" or ">"
but when i do :

if
[ $line = "[^<>]" ]
then
echo " no tags"
else
echo " tags"
fi

Every line i put in "line" ( including the ones with tags) are echoed as "no tags" !!!

same troubles with this :

sed -e '/[^<>]/d'

::evil::
 
Actually, [^<>] matches any line which contains any one character which is neither < or >. This is the vast majority of lines, excluding lines such as "<>" or "<<". If you want lines which contain neither character, you will have to match the lines which do contain either and throw them out. The pattern for matching tags would be [<>].

Also, you can't use regex patterns in shell scripting. You have to use sed, perl, or grep. Have you looked into using grep for this?
 
Back
Top