LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-14-2009, 10:48 AM   #1
paragkalra
Member
 
Registered: Sep 2006
Location: Nagpur, Maharashtra, India
Distribution: Debian, Ubuntu, Redhat, Fedora, SLES, OpenSUSE, FreeBSD, Mac OS X
Posts: 221

Rep: Reputation: 31
Matching white space through Grep


Hello All,

I am trying to match white space in patterns through - Grep

I tried [[:space:]] & [[:blank:]] but none of them worked.

Then I tried Perl extension '\s' and it worked.

So just wanted to know if [[:space:]] & [[:blank:]] are still supported or have they become deprecated.

However they have been mentioned in the man page so I guess I am not using it correctly. Any pointers on how to use them?
 
Old 11-14-2009, 11:19 AM   #2
paragkalra
Member
 
Registered: Sep 2006
Location: Nagpur, Maharashtra, India
Distribution: Debian, Ubuntu, Redhat, Fedora, SLES, OpenSUSE, FreeBSD, Mac OS X
Posts: 221

Original Poster
Rep: Reputation: 31
Ok got it fixed....

# cat /tmp/test.ldif

Quote:
dn: ou=71404558, ou=Company, ou=Personal, o=paragkalra.com
dn: ou=40208723, ou=Company, ou=Personal, o=paragkalra.com
dn: ou=63613012, ou=Company, ou=Personal, o=paragkalra.com
dn: ou=76884580, ou=Company, ou=Personal, o=paragkalra.com

As you can see there is space between 'dn:' and 'ou=' in all the lines

Initially I was placing '\*' after [[:space:]] as shown below:

Quote:
grep -i '^dn:[[:space:]]\*\(ou=[^,]\+,\)\{1\} ou=Company, ou=Personal, o=paragkalra.com' ous.ldif
Then I removed the black slash and it worked:

Quote:
grep -i '^dn:[[:space:]]*\(ou=[^,]\+,\)\{1\} ou=Company, ou=Personal, o=paragkalra.com' ous.ldif
Quote:
dn: ou=71404558, ou=Company, ou=Personal, o=paragkalra.com
dn: ou=40208723, ou=Company, ou=Personal, o=paragkalra.com
dn: ou=63613012, ou=Company, ou=Personal, o=paragkalra.com
dn: ou=76884580, ou=Company, ou=Personal, o=paragkalra.com
 
Old 11-14-2009, 11:42 AM   #3
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,187

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
Since your whole expression was written inside single quotes, which turns off bash parsing, (almost) all the backslash characters in your expression were passed to grep as literal backslash characters.

See info bash under "Quoting" for details.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Find/grep command to find matching files, print filename, then print matching content stefanlasiewski Programming 9 06-30-2016 05:30 PM
[SOLVED]matching a pattern with grep kdelover Programming 2 09-18-2009 06:07 AM
grep command for invert matching neeraj@linuxques Linux - Newbie 2 04-01-2009 08:25 AM
Matching a domain with grep abefroman Programming 2 11-06-2008 03:07 AM
omit white spaces for pattern matching in shell script bharatbsharma Programming 4 09-18-2008 08:25 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:49 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration