Regular Expression

Hi,

I have the following file as shown below:

Replace()
{
sed -e "s+ABCDIR+$DDIR/C+g" \
-e "s+ABCDIR+$DDIR/C+g" \
-e "s + ABCDDIR+$DDIR/C"\
}

I need a Regular expression to grep 0nly ABCDIR.
if i use grep -i "ABCDIR" it will display everything.
just i need the out put as only ABCDDIR.

Please help me in solving.

Thank you very much
Ravi

Hi,

if you want "ABCDDIR", you shouldn't use grep -i,
instead try:

grep -o "ABCDDIR"

HTH Chris

If I use grep -o. it is showing the below message

grep: illegal option -- o
Usage: grep -hblcnsviw pattern file . . .

You can use GNU grep, or you can use perl, which is easiest I think. This prints out ONLY the ABCDDIR text when found:

perl -n -e '/ABCDDIR/i && print $&,"\n";'  

In this case, you can use perl instead of sed -- this prints out the original text as you want it:

perl -p \
-e "s+ABCDIR+$DDIR/C+gi" \
-e "s+ABCDIR+$DDIR/C+gi" \
-e "s+ABCDDIR+$DDIR/C+gi"