Solved

search for data within files in linux

Posted on 2014-03-07
4
470 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
  • 2
4 Comments
 
LVL 31

Accepted Solution

by:
farzanj earned 250 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 77

Assisted Solution

by:arnold
arnold earned 250 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
Fine Tune your automatic Updates for Ubuntu / Debian
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

840 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