Jump to content

special character with grep


Guest Vaibhav
 Share

Recommended Posts

Guest Vaibhav

hi

 

I was learning about samba and I learnt that coders of SAMBA decided on its name by searching directory by using the command :-

grep -i "s.*m.*b.*" /home/dictionary/words

 

why they have used . (dot) here when there is no special character in books as . (dot) .

 

As by rules "s*m*b*" should work .

 

I also tried the command in a directory, where I added a new file sambar.dia.

using

ls | grep -i "s*m*b*" gave names of all the files or directories with s, m or b.

 

But by using

ls | grep -i "s.*m.*b.*"

I got the correct output (only a single file)

sambar .dia

 

Please tell me the explanation of this observance.

 

One more query please

In my mandrake 9.1 installation browsers(mozilla and Konqueror) are not able to access ftp sites. What may be the problem? Are settings to be changed to enable accessing FTP sites.

 

Thanks

Edited by Vaibhav
Link to comment
Share on other sites

Grep uses regular expressions which are a very powerful way of specifying your search. Check out Wikipedia for more info.

 

Basically, a dot . represents "any character" and an asterisk * represents "the previously mentioned character 0 or more times". So the regular expression

s.*m

matches an s, followed by any number of any character, followed by an m. If for example you had

sa*m

then it would match sm, sam, saaaaaaaaaaam and so on.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...