Sponsored Content
Full Discussion: Using grep in find
Top Forums UNIX for Beginners Questions & Answers Using grep in find Post 303043270 by RavinderSingh13 on Thursday 23rd of January 2020 04:34:50 AM
Old 01-23-2020
Hello big123456,

IMHO I think you are looking for grep -l option, since it will only print Filenames which have that specific text in them, try something like:

Code:
find /tmp/ -type f -exec grep -l "Give your text here..." {} \+ 2>/dev/null

In my tested case output was as follows.

Code:
/tmp/test_singh
/tmp/test1234

In above code change /tmp/ with your actual/complete path details and it should provide it in your output. Also I have kept 2>/dev/null for removing Errors its up to you in case you want to see errors on screen.

From man page of grep:

Quote:
-l, --files-with-matches
Suppress normal output; instead print the name of each input file from which output would normally have been printed. The scanning will stop on the
first match.

Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
 

10 More Discussions You Might Find Interesting

1. Programming

find and grep

Hi, I need to find out a particular pattern from a directory, for example say X. The X directory contains 10 c files, and it has subdirectory called Y, and Y has 20 c files within it. Now I have to find out the pattern only from parent directory X not from sub directory Y. I have... (4 Replies)
Discussion started by: sarwan
4 Replies

2. Shell Programming and Scripting

find then grep

I have some patterns that I need to match with the content of several files and I'm having trouble to do it Here is what I tried already : ksh won't even execute this #!/bin/ksh path="/export/home/ipomwbas" pattern=$path"/flags" find . -name "*.properties" |\ while read file; do ... (7 Replies)
Discussion started by: flame_eagle
7 Replies

3. UNIX for Dummies Questions & Answers

grep and find

Hey, I have a question about using grep and find together to locate all C programs in a directory containing certain words and open the vi editor with each file. I'm not sure how to do this in one command (as in one line). I know find has a "-exec" option that can call vi, but how do you combine... (1 Reply)
Discussion started by: MEllis5
1 Replies

4. UNIX for Dummies Questions & Answers

find , grep

HI what is the difference between find and grep if I want to find all the files from different directories which contain "ORA" error, and the line number in each file which has ORA error should I use pipeline ? thanks James (3 Replies)
Discussion started by: james94538
3 Replies

5. Shell Programming and Scripting

Using Find w/ Grep?

Hey, I have a Find command like: find $searchDir -type f and this returns a list of files under the directory, which is all good, but, I want to filter that search for files that contain the string "people" I tried something like: find $searchDir -type f -exec grep "people" '{}'... (2 Replies)
Discussion started by: beefeater267
2 Replies

6. UNIX for Dummies Questions & Answers

Using find with a grep

:wall:Hello, Im having trouble using the find and grep combined into one command. I have the following: find filname* -mmin -60 grep "ERROR" filename I want to find the "ERROR" text in any file created in the last hour in the current directory. I dont know how to end the command. If I leave... (3 Replies)
Discussion started by: aispg8
3 Replies

7. UNIX for Dummies Questions & Answers

grep or find ?

I have a file called 'test.txt' that contains alphanumeric charecters. The file contains the word 'SBE' followed by other alphabets many times. For example, the file will contain: SBE334GH and also will have SBE77Y8I. When i do grep 'SBE*' test.txt - it outputs the entire file. Can you... (5 Replies)
Discussion started by: DallasT
5 Replies

8. Shell Programming and Scripting

How to use grep & find command to find references to a particular file

Hi all , I'm new to unix I have a checked project , there exists a file called xxx.config . now my task is to find all the files in the checked out project which references to this xxx.config file. how do i use grep or find command . (2 Replies)
Discussion started by: Gangam
2 Replies

9. UNIX for Dummies Questions & Answers

find/xargs/*grep: find multi-line empty "try-catch" blocks - eg, missing ; not in a commented block

How can I recursively find all files in a directory and print out the file and first line number of any text blocks that match the below cases? This would seem to involve find, xargs, *grep, regex, etc. In summary, I want to find so-called empty "try-catch blocks" that do not contain code... (0 Replies)
Discussion started by: lifechamp
0 Replies

10. Shell Programming and Scripting

Find and Grep

Is it possible with find and Grep to search files under a directory and display only files that have multiple occurrence of a string (In AIX)? Anybody has an example code? If not what are the other options? Thanks in advance. (7 Replies)
Discussion started by: J_ang
7 Replies
pdfgrep(1)							   USER COMMANDS							pdfgrep(1)

NAME
pdfgrep - search pdf files for a regular expression SYNOPSIS
pdfgrep [OPTION...] PATTERN FILE... DESCRIPTION
Search for PATTERN in each FILE. PATTERN is an extended regular expression. pdfgrep works much like grep, with one distinction: It operates on pages and not on lines. OPTIONS
-i, --ignore-case Ignore case distinctions in both the PATTERN and the input files. -H, --with-filename Print the file name for each match. This is the default setting when there is more than one file to search. -h, --no-filename Suppress the prefixing of file name on output. This is the default setting when there is only one file to search. -n, --page-number Prefix each match with the number of the page where it was found. -c, --count Suppress normal output. Instead print the number of matches for each input file. Note that unlike grep, multiple matches on the same page will be counted individually. -C, --context NUM Print at most NUM characters of context around each match. The exact number will vary, because pdfgrep tries to respect word bound- aries. If NUM is "line", the whole line will be printed. If this option is not set, pdfgrep tries to print lines that are not longer than the terminal width. --color WHEN Surround file names, page numbers and matched text with escape sequences to display them in color on the terminal. (The default set- ting is auto). WHEN can be: always Always use colors, even when stdout is not a terminal. never Do not use colors. auto Use colors only when stdout is a terminal. -R, -r, --recursive Recursively search all files (restricted by --include and --exclude) under each directory. --exclude=GLOB Skip files whose base name matches GLOB. See glob(7) for wildcards you can use. You can use this option multiple times to exclude more patterns. It takes precedence over --include. Note, that in- and excludes apply only to files found via --recursive and not to the argument list. --include=GLOB Only search files whose base name matches GLOB. See --exclude for details. The default is *.pdf. --unac Remove accents and ligatures from both the search pattern and the PDF documents. This is useful if you want to search for a word containing 'ae', but the PDF uses the single character 'ae' instead. See unac(3) and unaccent(1) for details. [This option is experimental and only available if pdfgrep is compiled with unac support.] -q, --quiet Suppress all normal output to stdout. Errors will be printed and the exit codes will be returned (see below). --help Print a short summary of the options. -V, --version Show version information ENVIRONMENT VARIABLES
The behavior of pdfgrep is affected by the following environment variable. GREP_COLORS Specifies the colors and other attributes used to highlight various parts of the output. The syntax and values are like GREP_COLORS of grep. See grep(1) for more details. Currently only the capabilities mt, ms, mc, fn, ln and se are used by pdfgrep, where mt, ms and mc have the same effect on pdfgrep. EXIT STATUS
Normally, the exit status is 0 if at least one match is found, 1 if no match is found and 2 if an error occurred. But if the --quiet or -q option is used and a match was found, pdfgrep will return 0 regardless of errors. AUTHOR
Hans-Peter Deifel <hpdeifel at gmx.de> SEE ALSO
grep(1), regex(7) version 1.2 February 14, 2012 pdfgrep(1)
All times are GMT -4. The time now is 06:19 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy