Sponsored Content
Top Forums Shell Programming and Scripting How can I use find command to search string/pattern in a file recursively? Post 302982706 by RavinderSingh13 on Monday 3rd of October 2016 02:57:51 AM
Old 10-03-2016
Quote:
Originally Posted by cola
What's the difference between {} \; and {} + or {} \+ ?
Is it possible to call multiple commands with -exec like piping:
Code:
find . -type f -exec onecommand | secondcommand {} \;

What's wrong with using cat?
Hello cola,

Following are the answers for your queries.
  1. Difference between {} \+and{} \;is {} \+is faster than {} \;.
  2. Yes, it is possible to use multiple exec calls into a single findcommand, it is completely depends on your requirements.
  3. So there is something called UUOC (Useless use of cat), so using catcommand with a command which is able to read Input_file by itself it called UUOC in very short description. Following is an example for same. Let's say we have following Input_file.
Code:
cat  Input_file
abcdef
test test test1
test2 asajndjad
dwjfewygfwkcm wdjcwcnwnc

Now if want to look for string test in above Input_file then example of UUOC is as follows.
Code:
cat Input_file | grep "test"
test test test1
test2 asajndjad

Above will read the Input_file by catcommand then it will push the standard output of this command as standard input to next grepcommand(that's why pipe|is used here) which will then read file and search for string testthen. So point here is unnecessarily we are using catwhen grepitself is capable to read Input_file from itself. So by directly using grephere to read and search Input_file we could save sometime(depending upon you Input_file size) and processes too.

Now following is the example of grepwhich is capable of reading the Input_file by itself and search a string too.
Code:
grep "test"  Input_file
test test test1
test2 asajndjad

I hope this helps you.

Thanks,
R. Singh

Last edited by rbatte1; 10-03-2016 at 09:17 AM.. Reason: Converted to formatted number-list with LIST=i to give roman numerals
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Search Mulitiple String pattern in a file

Hi, I need to search for a multiple string pattern(5 key words) in a file(similar to a flat file) ,and i need to store the output in a another file . In that file we may have mutiple occurrences of the key words.and i need only the unique. kindly help out. Thanks, Mohana Krishnan (2 Replies)
Discussion started by: krishnan_6015@y
2 Replies

2. UNIX for Dummies Questions & Answers

String search - Command to find second occurance

Hi, I am new to Unix world. Is there any command which can directly return the second occurance of a particular string in a file? Basically, I want to read the contents of the file from the second occurance of a particualr string. Can be implemented using a loop, but am just wondering if there... (5 Replies)
Discussion started by: saurabhsinha23
5 Replies

3. Shell Programming and Scripting

find and replace a search string recursively in files

Hi , I have a directory structure as dir and subdirectories and files under it and so on.now I need to find the files which contain the search string under every dir and subdir and replace . my search string is like searchstring=/a/b string to be replaced=/a/c/b please help. ... (7 Replies)
Discussion started by: mohanpadamata
7 Replies

4. Shell Programming and Scripting

Using find command to search a pattern in group of files

Hi i am having a group of *.csh files under parent directory. Now i want to search a particular pattern in these group of *.csh files(suppose i need to search a pattern ABC - proj ). Can anyone please tell me how to do it using find command. Thanks in advance sarbjit (4 Replies)
Discussion started by: sarbjit
4 Replies

5. Shell Programming and Scripting

Awk search for string pattern in delimited file

I've got a semicolon delimited file. I would like to search for fields that match a pattern, and not hardcoded eg "mth". *th=something If the delimited field fulfills this condition, eg. mth=value I would like to print out both key and value for some number comparison. eg. if value > "12"... (5 Replies)
Discussion started by: alienated
5 Replies

6. Shell Programming and Scripting

how to find a pattern from an external file in a directory containing multiple file recursively

Hi, Need your help in this. I have an input file that has multiple enrollment_number, somewhat like 1234567 8901234 9856321 6732187 7623465 Now i have to search and delete these enrollment_number recursively from all the files that are within multiple sub-directories of a... (10 Replies)
Discussion started by: mukulverma2408
10 Replies

7. Shell Programming and Scripting

Search for a pattern in a String file and count the occurance of each pattern

I am trying to search a file for a patterns ERR- in a file and return a count for each of the error reported Input file is a free flowing file without any format example of output ERR-00001=5 .... ERR-01010=10 ..... ERR-99999=10 (4 Replies)
Discussion started by: swayam123
4 Replies

8. UNIX for Advanced & Expert Users

Recursively search the string from a column in no. of files

i have a file named keyword.csv(contains around 8k records) which contains a no. of columns. The 5th column contains all the keywords. I want to recursively search these keywords in all .pl files(around 1k) and display the filename....Afterthat i will use the filename and some of the column from... (3 Replies)
Discussion started by: millan
3 Replies

9. UNIX for Beginners Questions & Answers

Search strings from a file in files in a directory recursively; then print the string with a status

Hi All, I hope somebody would be able to help me. I would need to search a string coming from a file, example file.txt: dog cat goat horse fish For every string, I would need to know if there are any files inside a directory(recursively) that contains the string regardless of case.... (9 Replies)
Discussion started by: kokoro
9 Replies

10. Shell Programming and Scripting

Script to find string based on pattern and search for its corresponding rows in column

Experts, Need your support for this awk script. we have only one input file, all these column 1 and column 2 are in same file and have to do lookup for values in one file(column1 and column2) but output we need in another file Need to grep row whose string contains 9K from column 1. When found... (6 Replies)
Discussion started by: as7951
6 Replies
All times are GMT -4. The time now is 10:14 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy