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
Regex pppswing Shell Programming and Scripting 5 06-30-2008 11:22 PM
Regex deepakpv Shell Programming and Scripting 6 03-28-2007 05:18 AM
Regex?? Please help lunac UNIX for Dummies Questions & Answers 7 01-30-2007 01:13 PM
regex question arushunter Shell Programming and Scripting 8 01-04-2007 05:49 PM
sed regex Shakey21 UNIX for Dummies Questions & Answers 4 01-31-2002 09:16 PM

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 10-08-2008
anchal_khare anchal_khare is offline
Registered User
  
 

Join Date: Jun 2007
Location: Mumbai,India
Posts: 325
regex

hi frnds
i m having prb while matching a numerical num...

[0-9]+ is not working for me... ( ?? )

so i m achieving the criteria with [0-9]\{1,\} ( pl suggest if i m wrong )

nw the prb is.. i dont want to match the number with all zeros in it..
eg 00000 or 0000000 etc etc...

pl help..

Thanks..
Anchal.
  #2 (permalink)  
Old 10-08-2008
otheus's Avatar
otheus otheus is offline Forum Staff  
Moderator ala Mode
  
 

Join Date: Feb 2007
Location: Innsbruck, Austria
Posts: 1,891
What shell are you using? Are these files? Are these patterns in a file? Are you using grep, awk, perl, sed, bash, tcsh?
  #3 (permalink)  
Old 10-13-2008
anchal_khare anchal_khare is offline
Registered User
  
 

Join Date: Jun 2007
Location: Mumbai,India
Posts: 325
hi
i am working on bash shell on linux box.
i am applying this pattern to search for files with some specific format...

pl help
  #4 (permalink)  
Old 10-13-2008
otheus's Avatar
otheus otheus is offline Forum Staff  
Moderator ala Mode
  
 

Join Date: Feb 2007
Location: Innsbruck, Austria
Posts: 1,891
Refer to the man page section on "Pattern Matching", otherwise known in Shell parlance as "fileglob". The [0-9] is right, but "+" doesn't work here. To match a non-zero digit followed by more digits, you need:

Code:
shopt -s nullglob
echo [1-9][0-9]*

If you can have leading zeros, but you don't want to match one with ONLY 0's, then you can do:

Code:
shopt -s nullglob
echo [1-9][0-9]*  [0-9]*[1-9][0-9]*  [0-9]*[1-9]

This last one matches : (1) any number starting with a non-zero, AND (2) any number with a non-zero in the middle, AND (3) any number ending with a non-zero.

The shopt -s nullglob ensures that if the expression does not match, you get the empty string (instead of the pattern itself).
Closed Thread

Bookmarks

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 04:38 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