The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Regular Expressions ramky79 UNIX for Advanced & Expert Users 3 05-21-2008 05:13 PM
regular expressions melanie_pfefer UNIX for Dummies Questions & Answers 8 04-10-2008 04:24 AM
Regular Expressions sandeep_hi Shell Programming and Scripting 6 06-12-2006 02:12 AM
regular expressions in c++ szzz High Level Programming 2 10-06-2003 10:33 AM
Regular Expressions AresMedia Shell Programming and Scripting 1 08-22-2002 03:55 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-27-2007
bishweshwar bishweshwar is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 56
matching words using regular expressions

following file is taken as input

aaa bbb ccc
ddd eee ffff

grep -w aaa <filename> gives proper output.

grep \<\(aaa\).*\> filename :- should give output, since aaa is at begining, however i dosen't get any ouput.

Any discrepancy.

machine details:-
Linux anaconda 2.4.22-1.2115.nptlsmp #1 SMP Wed Oct 29 15:30:09 EST 2003 i686 i686 i386 GNU/Linux
  #2 (permalink)  
Old 12-27-2007
drl's Avatar
drl drl is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2007
Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 704
Hi.

The "\<" and "\>" are necessary for grep to see as part of the pattern. If you fail to quote them, the shell will remove the backslashes:
Code:
#!/usr/bin/env sh

# @(#) s1       Demonstrate grep with quoted word boundary assertions.

set -o nounset
echo

debug=":"
debug="echo"

## Use local command version for the commands in this demonstration.

echo "(Versions displayed with local utility \"version\")"
version >/dev/null 2>&1 && version bash

echo
FILE=${1-data1}
echo " Input file $FILE:"
cat $FILE

echo
echo " Results from grep -w:"
grep -w aaa $FILE

echo
echo " Results from grep word boundary assertions quoted:"
grep "\<aaa\>" $FILE

echo
echo " Unquoted and quoted backslashes:"
echo \< and "\<"

exit 0
Producing:
Code:
% ./s1

(Versions displayed with local utility "version")
GNU bash 2.05b.0

 Input file data1:
aaa bbb ccc
ddd eee ffff

 Results from grep -w:
aaa bbb ccc

 Results from grep word boundary assertions quoted:
aaa bbb ccc

 Unquoted and quoted backslashes:
< and \<
Quoting can be confusing until one practices by writing a lot of commands and shell scripts ... cheers, drl
Closed Thread

Bookmarks

Tags
regex, regular expressions

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 06:01 AM.


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