LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 10-06-2018, 02:52 PM   #1
kenw232
Member
 
Registered: May 2006
Posts: 125

Rep: Reputation: 12
How to grep -E for this?


I am trying to grep for ${"\x47 in this string on the command line with find.

Code:
global $icf9;$icf9 = $GLOBALS;${"\x47\x4c\...
This will partially work but I can't add the ${ before it. I've tried everything.

Code:
find . -name "*.php" -exec grep -HEsi """\x47" {} \;
Anyone have an idea?
 
Old 10-06-2018, 04:24 PM   #2
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,750

Rep: Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222
It would help if you showed us what you've tried, and the results of those attempts. Your implicit "doesn't work" isn't helpful

Absent your sharing: escape them
Code:
\$\{
(untested)
 
Old 10-06-2018, 04:28 PM   #3
kenw232
Member
 
Registered: May 2006
Posts: 125

Original Poster
Rep: Reputation: 12
I tried my example only (find . -name "*.php" -exec grep -HEsi """\x47" {} \ which works but I need to add the ${ before it. whenever I do that it finds nothing. I have tried what you said and it does not work either (finds nothing). To be clear the files I'm searching have that top line of text in my OP. I want to grep for it with this now:

find . -name "*.php" -exec grep -HEsi "\$\{""\x47" {} \;

it should find it and it doesn't.
 
Old 10-06-2018, 05:32 PM   #4
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,750

Rep: Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222
Please use code tags when posting code or results...they prevent the spurious smileys, among other things.
Does
Code:
find . -name "*.php" -exec grep -HEsi """\x47" {} \;
return other lines than what you're wanting to match?

I think the problem is using quote delimiters and having a quote in the pattern.
Using single quotes works.
Note that it was necessary to also escape the \. Without that, the \x just meant x, so there was no match to the \ character
Code:
find . -name "*.php" -exec grep -HEsi '\$\{"\\x47';

Last edited by scasey; 10-06-2018 at 05:35 PM.
 
Old 10-06-2018, 07:01 PM   #5
kenw232
Member
 
Registered: May 2006
Posts: 125

Original Poster
Rep: Reputation: 12
thanks, that seems to work better.
 
Old 10-06-2018, 07:48 PM   #6
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,750

Rep: Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222
You're welcome.
Mastering regex often involves a lot of trial and error.

You can mark the thread Solved, if you feel it is.
 
Old 10-06-2018, 10:12 PM   #7
individual
Member
 
Registered: Jul 2018
Posts: 315
Blog Entries: 1

Rep: Reputation: 233Reputation: 233Reputation: 233
Here's a tip: you don't need -E because your pattern is fixed. Rather than use -E and then have to escape the meta characters ($, {, \), use the -F flag, which means "fixed pattern."
Code:
grep -F '${\x47'
Much easier to read, isn't it?
 
2 members found this post helpful.
Old 10-07-2018, 03:16 AM   #8
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
you are grepping for a fixed string, yes?
it's not a regular expression?
so why use -E?
wouldn't -F be better?
Code:
grep -F '${"\x47' ...
edit: ooooops, the previous poster wrote exactly the same

Last edited by ondoho; 10-07-2018 at 03:18 AM.
 
Old 10-07-2018, 04:05 AM   #9
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,750

Rep: Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222
One more: -H specifies the default...
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
from ps -ef | grep java how can I grep out Xms & Xmx value hjo99729 Linux - Newbie 3 10-26-2017 07:39 PM
Find & grep - how to return pathes, not grep phrases ? postcd Linux - General 2 11-25-2014 12:43 PM
grep to file outputs more than grep to screen? tcpman Linux - Server 4 06-07-2013 04:46 AM
Creating an alias in ksh that uses grep and includes 'grep -v grep' doug248 Linux - Newbie 2 08-05-2012 02:07 PM
Trying to understand pipes - Can't pipe output from tail -f to grep then grep again lostjohnny Linux - Newbie 15 03-12-2009 10:31 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:24 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