Solved

search for data within files in linux

Posted on 2014-03-07
4
469 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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
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…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

809 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