guys,
my requirment goes like this:
I have a file, and wish to filter out records where
- The first letter is o or O
and
- The next 4 following letter should not be ther
I do not wish to use pipe and wish to do it in one shot.
The best expression I came up with is:
grep ^[oO][^tT][^hH][^eE][^rR]* test1
But with this there is a problem if the word is beginning with o and less then 4 letters it excludes those.
Thanks in advance to the R.E gurus
rishi
Thanks Vino for suggestion, but this will not satisfy my requirment:
say my file has
one
only
fine
other
clear
output
o
the result of search should be
one
only
output
o
suppose if i go the way you suggest it will also include "clear" i.e the word not beginning with "o"
hope this sample clarifies the question
rishi
vino
4
So your list will only contain words and not lines/sentences ?
grep -v -i 'other' test1 | grep '^[oO]'
If running 2 greps is acceptable
vino
7
[~/temp]$ cat rishi.txt
one
only
fine
other
clear
output
o
[~/temp]$ sed -n -e '/[oO][tT][hH][eE][rR]/d' -e '/[oO]/p' rishi.txt
one
only
output
o
Will print lines having an o or O.
or
awk '/^[oO]/ && ! /^.[Tt][Hh][Ee][Rr]/{ print;}' test1
should work too.
how abt this
sed '/[Oo][Tt][Hh][Ee][Rr]/d; /^[Oo]/!d' <file>
reborg
10
grep -viE "^[^o]|^other" file
or
egrep -viE "^[^o]|^other" file
depending on your system