The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Regular expression Help Harikrishna Shell Programming and Scripting 3 06-11-2008 09:20 AM
regular expression jaber87 Shell Programming and Scripting 3 06-05-2008 04:07 AM
regular expression (.*?) uttamhoode Shell Programming and Scripting 7 06-04-2008 05:11 AM
Regular expression Harikrishna Shell Programming and Scripting 2 05-31-2008 08:10 AM
Regular Expression + Aritmetical Expression Z0mby Shell Programming and Scripting 2 05-21-2002 11:59 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-05-2009
ravi_rn ravi_rn is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 19
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
  #2 (permalink)  
Old 01-05-2009
Christoph Spohr Christoph Spohr is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 205
Hi,

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


Code:
grep -o "ABCDDIR"

HTH Chris
  #3 (permalink)  
Old 01-05-2009
ravi_rn ravi_rn is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 19
If I use grep -o. it is showing the below message

grep: illegal option -- o
Usage: grep -hblcnsviw pattern file . . .
  #4 (permalink)  
Old 01-05-2009
otheus's Avatar
otheus otheus is offline Forum Staff  
Moderator ala Mode
  
 

Join Date: Feb 2007
Location: Innsbruck, Austria
Posts: 1,889
You can use GNU grep, or you can use perl, which is easiest I think. This prints out ONLY the ABCDDIR text when found:

Code:
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:

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

Closed Thread

Bookmarks

Tags
grep or

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:28 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0