Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Find file dont have that string Post 303033667 by rbatte1 on Wednesday 10th of April 2019 06:10:29 AM
Old 04-10-2019
Hello Sagar Singh,

These are obviously demonstration files to me. Will the live files actually have more than just a single line with/without Hello Sagar in them?

You might need a simple loop to check each in turn and return the filenames you are looking for, e.g.:
Code:
#!/bin/bash

# Define list of files.  This could be pattern matched if more appropriate
file_list="file01 file02 file03 file04 file05 file06 file07"

# This can be an extended regular expression, depending on your needs
search_expression="Hello Sagar"

for file in ${file_list}                                     # Not quoted to allow for filename expansion, however will have a problem with filenames containing whitespace.
do
   grep -Eq "${search_expression}" "${file}" || printf "File %s does not contain expression \"%s\"\n"  "${file}"  "${search_expression}"
done

From the following input files shown with more f*|more:-
Code:
::::::::::::::
file01
::::::::::::::
Hello Sagar
::::::::::::::
file02
::::::::::::::
Hello Sagar
I will ignore this file
::::::::::::::
file03
::::::::::::::
This file should be found
::::::::::::::
file04
::::::::::::::
Not starting the line Hello Sagar
::::::::::::::
file05
::::::::::::::
Hello Sagar not ending the line
::::::::::::::
file07
::::::::::::::
Hello Sagar

..... I get the following output from the above:-
Code:
$ pwd
/tmp/unix281673
$ ./search
File file03 does not contain expression "^Hello Sagar$"
File file04 does not contain expression "^Hello Sagar$"
File file05 does not contain expression "^Hello Sagar$"
grep: file06: No such file or directory
File file06 does not contain expression "^Hello Sagar$"

If this gives you the sort of thing you need, you may care to extend it to check that the files exists before running the grep just to tidy it up.



Does this help?

Robin
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

dont't find right regex

I have a string which contains following information: <SZ.T><P ALIGN="CENTER"><FONT FACE="Arial, Helvetica, sans-serif" SIZE="+3">Bundesregierung nimmt sich dicke Deutsche vor</FONT></P></SZ.T> <SZ.UT><P ALIGN="CENTER"><FONT SIZE="+1"><I> Seehofer und Schmidt planen Kampagne gegen... (3 Replies)
Discussion started by: trek
3 Replies

2. UNIX for Dummies Questions & Answers

Search for Files that DONT contain a string

How do I search for files that dont contain a certain string? I am currently trying find ./logs -size +1c -exec grep -l 'Process Complete' {} \; -exec ls -l {} \; > $TOD Which gives me files that are reater han 0 file size and contain the string 'Process complete' but I want files that DONT... (13 Replies)
Discussion started by: tonydsam
13 Replies

3. Shell Programming and Scripting

How to find a certain string in a file and replace it with a value from another file using sed/awk?

Hi Everyone, I am new to this forum and new to sed/awk programming too !! I need to find particular string in file1(text file) and replace it with a value from another text file(file2) the file2 has only one line and the value to be replaced with is in the second column. file 1: (assert (=... (21 Replies)
Discussion started by: paramad
21 Replies

4. Linux

Find String in FileName and move the String to new File if not found

Hi all, I have a question.. Here is my requirement..I have 500 files in a path say /a/b/c I have some numbers in a file which are comma seperated...and I wanted to check if the numbers are present in the FileName in the path /a/b/c..if the number is there in the file that is fine..but if... (1 Reply)
Discussion started by: us_pokiri
1 Replies

5. Shell Programming and Scripting

Find multiple string in one file using find command

Hi, I want find multiple string in one file using find coomand. And keeping it in one variable.grep is not working. (5 Replies)
Discussion started by: vivek1489
5 Replies

6. UNIX for Dummies Questions & Answers

How to find a file if we dont know exact location of file ?

Hi I want know "How to find a file if we dont know exact location of file ?" Thanks, Tushar Joshi:) (9 Replies)
Discussion started by: tusharjoshi
9 Replies

7. Shell Programming and Scripting

find string and replace with string in other file

Dear all, I need your help, I have file like this: file1:23456 01910964830098775635 34567 01942809546554654323 67589 26546854368698023653 09778 58716868568576876878 08675 86178546154065406546 08573 54165843543054354305 . .file2: 23456 25 34567 26 67589 27 (2 Replies)
Discussion started by: attila
2 Replies

8. Shell Programming and Scripting

Find string in file and append new string after

Hi All, I'm trying to insert a string into a file at a specific location. I'd like to add a string after the parent::__construct(); in my file. <?php if (! defined('BASEPATH')) exit('No direct script access allowed'); class MY_Controller extends CI_Controller { function... (6 Replies)
Discussion started by: jjkilpatrick
6 Replies

9. Shell Programming and Scripting

Find string in file and find the all records by string

Hello I would like to get know how to do this: I got a big file (about 1GB) and I need to find a string (for instance by grep ) and then find all records in this file based on a string. Thanks for advice. Martin (12 Replies)
Discussion started by: mape
12 Replies

10. Shell Programming and Scripting

Perl script to read string from file#1 and find/replace in file#2

Hello Forum. I have a file called abc.sed with the following commands; s/1/one/g s/2/two/g ... I also have a second file called abc.dat and would like to substitute all occurrences of "1 with one", "2 with two", etc and create a new file called abc_new.dat sed -f abc.sed abc.dat >... (10 Replies)
Discussion started by: pchang
10 Replies
DtEditorInvokeFindChangeDialog(library call)							      DtEditorInvokeFindChangeDialog(library call)

NAME
DtEditorInvokeFindChangeDialog -- display the DtEditor widget dialog for searching and replacing text SYNOPSIS
#include <Dt/Editor.h> void DtEditorInvokeFindChangeDialog( Widget widget); DESCRIPTION
The DtEditorInvokeFindChangeDialog function displays the Find/Change dialog for the DtEditor widget. This dialog enables a user to search for, and optionally replace, a string in the text for the DtEditor widget. It also allows the user to specify a replacement string, which can be substituted for either the next occurrence of the search string or all occurrences. The Find/Change dialog remains displayed until the user closes it. For a complete description of the Find/Change dialog see DtEditor. Subsequent searches for the last search string entered can be made by calling DtEditorFind(3). Subsequent substitutions can be made with DtEditorChange(3). The widget argument specifies the DtEditor widget ID. For a complete definition of the DtEditor widget and its associated resources, see DtEditor(3). RETURN VALUE
The DtEditorInvokeFindChangeDialog function returns no value. SEE ALSO
Dt/Editor.h - DtEditor(5), DtEditor(3), DtEditorChange(3), DtEditorFind(3). DtEditorInvokeFindChangeDialog(library call)
All times are GMT -4. The time now is 01:42 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy