?
Solved

search for data within files in linux

Posted on 2014-03-07
4
Medium Priority
?
483 Views
Last Modified: 2014-03-07
hello there,
I would like to know how can I search only .php files using a command like this

grep -r -i "cHRVa2RQVjNSb1YwVndi" * | cut -d: -f1


I tried using this, and it works but doesnt show file path
find . -name '*.php' -exec grep "RnBOYms1d1V6Rk9jMDR3VG" {} \;
0
Comment
Question by:XK8ER
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 31

Accepted Solution

by:
farzanj earned 1000 total points
ID: 39914155
Try:

find . -name '*.php' -exec grep -H "RnBOYms1d1V6Rk9jMDR3VG" {} \;

Open in new window

0
 
LVL 1

Author Comment

by:XK8ER
ID: 39914159
any way to only display the file and not data?
0
 
LVL 31

Expert Comment

by:farzanj
ID: 39914163
Yes,
grep -l

lower case L option
0
 
LVL 79

Assisted Solution

by:arnold
arnold earned 1000 total points
ID: 39914168
-l is the flag for grep to return the filename where the pattern exists.

What do you need to do with this?

It might be simpler if you provide details on what it is you wanto achieve.

Do you need to to replace the pattern with a new pattern?

perl -pi.bak -e 's/pattern/replacement/g;' *

 test on a single file first.  Files where the match is made will be duplicated with a .bak suffix.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
BIND is the most widely used Name Server. A Name Server is the one that translates a site name to it's IP address. There is a new bug in BIND (https://kb.isc.org/article/AA-01272), affecting all versions of BIND 9 from BIND 9.1.0 (inclusive) thro…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses
Course of the Month10 days, 5 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question