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 Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Grepping the last 30 minutes of a log file... jtelep Shell Programming and Scripting 2 03-06-2008 12:27 AM
Loop and grepping into a file skotapal Shell Programming and Scripting 3 08-26-2002 10:28 PM
grepping the first 3 characters from a file rachael UNIX for Dummies Questions & Answers 2 10-15-2001 03:33 PM
grepping the first 3 characters from a file g-e-n-o UNIX for Dummies Questions & Answers 2 10-15-2001 07:11 AM
Deleting a File with an Erroneous Period PLF UNIX for Dummies Questions & Answers 3 08-09-2001 03:04 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 11-30-2007
bobk544 bobk544 is offline
Registered User
  
 

Join Date: Jan 2006
Location: fairfax virginia
Posts: 58
grepping for period . in file name ? ie grep .

hello,
this works ok where i'm greping for the ./ :
HTML Code:
export m1="./xyz.java "
echo  $m1 | grep ./ > /dev/null
if [ $? = 0 ]; then
     echo $m1
fi
but this doesn't where i'm just greping for the period . and i also tried .\
HTML Code:
export m1="xyz.java "
echo  $m1 | grep . > /dev/null
if [ $? = 0 ]; then
     echo $m1
fi
any ideas on how to wrap the . so it's not treated as a file reference or parm or whatever is happening there please?

thanks
bk
  #2 (permalink)  
Old 11-30-2007
bobk544 bobk544 is offline
Registered User
  
 

Join Date: Jan 2006
Location: fairfax virginia
Posts: 58
ok i think i have it i put the period in a variable ie:

grep $p

thanks
bk
  #3 (permalink)  
Old 11-30-2007
$antaclau$'s Avatar
$antaclau$ $antaclau$ is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 4
or simply try putting the searching pattern withing quotes

echo $m1 | grep "." > /dev/null





Tada
$anta
  #4 (permalink)  
Old 11-30-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: 711
Hi.

In regular expressions with grep, the "." (period, dot, full-stop) matches any single character (except newline), so you will need to provide an escape that grep will encounter, thereby effectively removing the normal "magic" of the ".".
Use
Code:
"\."
(with quotes) as that escaped sequence.

Here's an example:
Code:
#!/usr/bin/env sh

# @(#) s1       Demonstrate dot with grep regular expressions.

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 my-nl grep

echo

# Create data file data1

cat >data1 <<EOF
Hello, world.
Two, no dot: Hello, world (this line should not be matched)
Next line empty (this line and the next should not be matched)

Next line just a dot.
.
Last line here.
EOF

echo
echo " Numbered input file:"
my-nl data1

echo
echo " grep with just a dot:"
grep -n . data1

echo
echo " grep with escaped dot, but not quoted:"
grep -n \. data1

echo
echo " grep with escaped dot, double quotes:"
grep -n "\." data1

exit 0
which produces:
Code:
% ./s1

(Versions displayed with local utility "version")
GNU bash 2.05b.0
my-nl (local) 296
grep (GNU grep) 2.5.1


 Numbered input file:

==> data1 <==

  1 Hello, world.
  2 Two, no dot: Hello, world (this line should not be matched)
  3 Next line empty (this line and the next should not be matched)
  4
  5 Next line just a dot.
  6 .
  7 Last line here.

 grep with just a dot:
1:Hello, world.
2:Two, no dot: Hello, world (this line should not be matched)
3:Next line empty (this line and the next should not be matched)
5:Next line just a dot.
6:.
7:Last line here.

 grep with escaped dot, but not quoted:
1:Hello, world.
2:Two, no dot: Hello, world (this line should not be matched)
3:Next line empty (this line and the next should not be matched)
5:Next line just a dot.
6:.
7:Last line here.

 grep with escaped dot, double quotes:
1:Hello, world.
5:Next line just a dot.
6:.
7:Last line here.
To see the details, run as:
Code:
sh -vx s1
Best wishes ... cheers, drl

Last edited by drl; 11-30-2007 at 09:52 PM.. Reason: Add how to see details.
  #5 (permalink)  
Old 11-30-2007
gus2000 gus2000 is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 157
You must either escape the special characters, or tell grep use match ordinary strings instead of regex patterns:

Code:
grep "aaa\.bbb" myfile.txt
grep -F "aaa.bbb" myfile.txt
  #6 (permalink)  
Old 12-01-2007
bobk544 bobk544 is offline
Registered User
  
 

Join Date: Jan 2006
Location: fairfax virginia
Posts: 58
wow thanks all this is one awesome forum, happy weekend all!
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 11:12 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