LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices



Reply
 
Search this Thread
Old 12-05-2010, 12:14 PM   #1
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,290

Rep: Reputation: 50
Making grep find files containing '$' (the dollar sign char).


grep (GNU grep) 2.5

Hi:
I want to find files containing the "$" char (ascii 0x24). 'Grep -irl $ *' would output the names of every file in path *, of course, because it means end of line (EOL). So giving grep the string "$" won't do. So I tried 'grep -irl \$ *'. But this doesn't work either and I do not understand why. Am I not escaping the dollar sign? grep should interpret it literally. Neither 'grep -irl "$" *' will work. Fortunately, there's LQ, besides grep's man page. Any hint? Thanks for reading.

Last edited by stf92; 12-05-2010 at 12:46 PM.
 
Old 12-05-2010, 12:22 PM   #2
AlucardZero
Senior Member
 
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,653

Rep: Reputation: 536Reputation: 536Reputation: 536Reputation: 536Reputation: 536Reputation: 536
There's some sort of tomfoolery going on not just with grep, but with your shell, because $ denotes a variable. This will work:

Code:
grep -irl \\$ *
I imagine it's because you want grep to get that \, not the shell, though I'm not sure what the shell is doing with it.
 
Old 12-05-2010, 12:35 PM   #3
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,290

Original Poster
Rep: Reputation: 50
That certainly worked and I thank you. But can somebody tell me what \$ is to grep? If \$ is a var name, then a second backslash will take away that meaning, leaving this one: escaped dollar sign; which in turn takes away the meaning "end of line" leaving a mere dollar sign. But is \$ really a var name to bash (or to the shell)?

EDIT: I'm very sorry. It's all wrong. I reread AlucardZero's post and think I've now got it right.

EDIT 2: one thinks LQers will get bored with the whole story, but sometimes it's the best option. So here it goes:
I know some ebook in the HDD contains this line:
Quote:
for i in $FILE
which is part of a script I want to consult. And so the need for grep. That's all.

Last edited by stf92; 12-05-2010 at 12:47 PM.
 
Old 12-05-2010, 12:48 PM   #4
AlucardZero
Senior Member
 
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,653

Rep: Reputation: 536Reputation: 536Reputation: 536Reputation: 536Reputation: 536Reputation: 536
The $ character in regular expressions denotes the end of the line, so you have to escape it to search for a literal $.

But like I said, not sure exactly what's going on with the shell.
 
1 members found this post helpful.
Old 12-05-2010, 01:04 PM   #5
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,290

Original Poster
Rep: Reputation: 50
Well, maybe you're not sure. But I'll keep this thread anyways in my hard disk. Regards.
 
Old 12-05-2010, 10:37 PM   #6
mahu_mahu
Member
 
Registered: Dec 2007
Location: Japan
Distribution: Debian
Posts: 42

Rep: Reputation: 3
When you invoke
Code:
grep -irl \$ *
at first shell translates \$ to $ and give it to grep.
So above code is equivalent to
Code:
grep -irl $ *
But if you invoke
Code:
grep -irl \\$ *
shell translates \\ to \ and gives '-irl \$ *' to grep.
and you can get what you want.
 
2 members found this post helpful.
Old 12-05-2010, 11:32 PM   #7
crts
Senior Member
 
Registered: Jan 2010
Posts: 1,604

Rep: Reputation: 446Reputation: 446Reputation: 446Reputation: 446Reputation: 446
Hi,

alternatively you could use single quotes
Code:
grep '\$' file
This way bash will not try to interpret anything between the single quotes but just pass it "as is" to grep.
 
1 members found this post helpful.
Old 12-06-2010, 05:07 AM   #8
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,290

Original Poster
Rep: Reputation: 50
All this is highly instructive, and thanks be given to these wonderful LQers. But then a question arises: how to know, save by careful study of a manual page, as of now several thousand lines long, the scope of things "eaten" by the shell and, therefor, what is left to programs like grep?

I presume ignorance interrogates once and again.
 
Old 12-06-2010, 08:59 PM   #9
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.6, Centos 5.10
Posts: 16,324

Rep: Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041
http://tldp.org/LDP/abs/html/special-chars.html

Enjoy
 
1 members found this post helpful.
Old 12-08-2010, 12:16 PM   #10
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,290

Original Poster
Rep: Reputation: 50
Thanks Chris for the link, and may I not have to fall back on LQ so heavily in the future.
 
  


Reply

Tags
grep


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Problem Searching for php files with Find and Grep ssmela Linux - General 3 11-02-2010 02:55 PM
Howto find out files that are changed less than 10 hours with grep command coolloo_djack Programming 1 03-20-2010 02:05 PM
Find/grep/wc command to find matching files, print filename and word count dbasch Linux - Newbie 10 09-14-2009 06:55 PM
searching within files. cat grep find w3bd3vil Linux - Newbie 4 10-13-2008 04:59 AM
Xubuntu char set support (pound sign) peoplesrepublican Ubuntu 1 12-15-2006 07:58 AM


All times are GMT -5. The time now is 03:53 AM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration