Find file dont have that string


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Find file dont have that string
# 1  
Old 04-09-2019
Find file dont have that string

I have 13 text files and almost all of them contain the same string.
but some file has diffrent string inside.
I want to send that file which has a diffrent string inside
# 2  
Old 04-09-2019
Quote:
Originally Posted by Sagar Singh
I have 13 text files and almost all of them contain the same string.
but some file has diffrent string inside.
I want to send that file which has a diffrent string inside
Hello Sagar,

Request you to please do always provide 3 important things required by the forums.

1st- Sample of Input_file(which has your sample input(s) etc) in CODE TAGS.

2nd- Sample of your expected output(which should come after running script/code) in CODE TAGS too.

3rd- Most important thing, your efforts. We encourage all users to add their efforts which they have put in order to solve their own problems in their posts in CODE TAGS, don't bother either your written code(s) are correct or wrong just post them in your posts and when you get guidance from this community then you could see where you were lacking or missing the things etc and that's the thought behind it(LEARNING).

Kindly do mention all details mentioned above clearly in your post and do let us know I am pretty sure you will get good guidance on this site, Keep learning, keep sharing on this site, cheers Smilie


Thanks,
R. Singh
# 3  
Old 04-09-2019
Hello R.Singh sir,
Code:
file01
Hello Sagar

file02
Hello Sagar

file03
Hello Rohit

file04
Hello Sagar

file 05
Hello Vishal

file06 

file07
Hello Sagar

++++++++++++++++++++++++++++++++++++++++++++++++++

These are my 7 input file,
I want the file which does not contain "Hello Sagar" as an Output file

Code Used by me
Code:
grep "Hello Sagar"  file0?

to get the file contain "Hello Sagar"
After that i am unable to proceed

Moderator's Comments:
Mod Comment Kindly do wrap your samples in CODE TAGS.
# 4  
Old 04-09-2019
Hello Sagar Singh,

Could you please try following(not tested it though).
Code:
grep -L "Hello Sagar" *

Thanks,
R. Singh
# 5  
Old 04-09-2019
Input files

file01
Code:
Hello Sagar

file02
Code:
Hello Sagar

file03
Code:
Hello Rohit

file04
Code:
Hello Sagar

file 05
Code:
Hello Vishal

file06
Code:


file07
Code:
Hello Sagar

=======================================================


Output required

Code:
file03
Hello Rohit

file 05
Hello Vishal

file06


==============================

how can I get that files as output which do not contain " Hello Sagar"

Last edited by Don Cragun; 04-10-2019 at 01:41 AM.. Reason: Add CODE and ICODE tags.
# 6  
Old 04-10-2019
Hello Sagar Singh,
I am having difficulty understanding what you are trying to do.

In post #1 you said you have thirteen files to search. In post #3 you said you have seven files and sort of showed us their contents. It seems that you are saying that each of your input files has a filename that is the string file followed by two octal or decimal digits, each file contains exactly one line of text, and if that line of text is not " Hello Sagar you want to print the filename and the contents of each file that does not contain that text and only that text with each output filename and contents separated from other filenames and their contents by an empty line of text.

But since none of your sample input files contain the leading <space> character that you say must be present, it would seem that the output should include every input file that you have shown us.

Have I understood your requirements correctly?

If you are not looking for a leading <space> character before "Hello Sagar" and just want a list of lines in file that do not contain the fixed string "Hello Sagar", then the command:
Code:
grep -Fv "Hello Sagar"

would give you a list of files that contain lines that do not match your pattern with the filename prepended to each line that does not match.

If you just want the filenames of files that do not contain your pattern, the code Ravinder suggested my be exactly what you want, but the grep -L option is an extension to the standards and will not be available on all systems. And, since you haven't told us what operating system you're using, we can't know if his suggestion will work in your environment.

If you really want the output to contain empty lines between the filenames and contents of each file that does not contain any line that matches your pattern, we could help you write a shell script that would do that, but we would need to know what shell you are using as well as what operating system you're using.

In your first post in this thread you said: "I want to send that file which has a diffrent string inside". Where do you want to send those files?

Please help us help you by providing details about the operating system you' are using, the shell you are using, more details about the format of the files you are processing, and an English description of the output you are trying to produce.
This User Gave Thanks to Don Cragun For This Post:
# 7  
Old 04-10-2019
Quote:
Originally Posted by Don Cragun
If you just want the filenames of files that do not contain your pattern, the code Ravinder suggested my be exactly what you want, but the grep -L option is an extension to the standards and will not be available on all systems.
All grep implementations i have seen so far have ":" (colon) as the separator between the matched contents and the filename (to be honest i don't know if this is required by the standards or just convention), so:

Code:
grep -Fv <fileglob here> | cut -d':' -f1

should provide a standards-conformant alternative to grep -L, no??

I hope this helps.

bakunin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
Login or Register to Ask a Question