Solved

command to search all files in folders and sub folders for a series of strings

Posted on 2014-01-15
2
271 Views
Last Modified: 2014-01-15
Hi

I want to look for a series of strings in a set of files and i'm not used to using the command line. In other words I want to look for 'term1' or 'term2' in all the files in a directory and its sub directory. I'd like to pipe the results into a text file too.

I havent used limux for ages so I don't know whether to use find or grep or awk.

Any advice much appreciated

thanks
0
Comment
Question by:andieje
2 Comments
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
ID: 39782970
find /directory -type f | xargs grep -E 'term1|term2' > outputfile

The above will show the matching content along with the filenames. If you want to see just the names of files with matching content, but not the content itself use

find /directory -type f | xargs grep -El 'term1|term2' > outputfile

/directory is the directory where the search should start.
0
 
LVL 48

Expert Comment

by:Tintin
ID: 39783936
or simply

grep -Er 'term1|term2' /directory >outputfile
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

rdate is a Linux command and the network time protocol for immediate date and time setup from another machine. The clocks are synchronized by entering rdate with the -s switch (command without switch just checks the time but does not set anything). …
I am a long time windows user and for me it is normal to have spaces in directory and file names. Changing to Linux I found myself frustrated when I moved my windows data over to my new Linux computer. The problem occurs when at the command line.…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
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.

910 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now