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.:
From the following input files shown with more f*|more:-
..... I get the following output from the above:-
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.
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:
should provide a standards-conformant alternative to grep -L, no??
I hope this helps.
bakunin
Supposed the -l option is standard, then the following is better
But it is not the same as
if there are files with matching and not matching lines.
The following function emulates it
This User Gave Thanks to MadeInGermany For This Post:
Hi Robin, MadeInGermany, & bakunin,
Isn't it amazing how hard it is to understand how a common utility like grep works even though we all use it several times a day?
For the record, the standard NAME and SYNOPIS sections for grep are:
First note that the vertical bars between -E and -F and between -c, -l, and -q indicate that grep has two sets of mutually exclusive options. And since nothing in the description of grep says otherwise, this means that if you invoke grep with both of those capital letter options or if you invoke grep with more than one of those three mutually exclusive lowercase options, the behavior is completely undefined.
The standard requires that when none of the -c, -l, and -q options is specified AND two or more file operands are present when grep is invoked, each line meeting the criteria will be output on a line that starts with the name of the file it came from immediately followed by a <colon> character. And, if the -n option is also specified, that is followed by the line number of the line in that was selected immediately followed by a colon. And then, the contents of the selected line are also written to that output line. It is not clear to me exactly what the requirements are if the -n option is specified along with one of the three mutually exclusive lowercase letter options.
As you can see, the -l option is included in the standard, but the output it produces is just the names of files that contain at least one line that meets the specified match criteria. Unfortunately this means that one of:
probably does exactly what Sagar Singh wants, but we don't know if the grep utility on his system recognizes the -L option, we aren't sure whether the fixed string to be used for the search pattern should contain a leading <space>, and we aren't sure whether Sagar Singh wants to know about lines that do not contain the search pattern, about lines that are not an exact match (with no other leading or trailing characters), nor whether any of his seven or thirteen input files might be empty files.
Note that if and only if there its no possibility that an empty file will ever be evaluated for this project, then:
is equivalent to:
and:
is equivalent to:
If there might be empty files and the requirement is to list files that do not contain any line meeting the match criteria, the commands using the -l instead of the -L option will not fully meet the requirements. But, I am hesitant to try to reinvent the -L option until Sagar Singh confirms that that is what is needed and that grep on the system he is using does not already support the -L option.
Hello Sagar Singh,
Please tell us what operating system and shell you're using and clarify exactly what you are trying to do so we can help you create a script that will meet your needs.
Sincerely,
Don
This User Gave Thanks to Don Cragun For This Post:
Don, the difference is with empty files and multi-line files:
Only the one-line files a1 and b1 behave the same.
Yes. I apologize for being vague. What I should have said was:
The grep -Flv "a" ... will list a file operand if that file contains one or more lines that do not contain "a".
The grep -FL "a" ... will list a file operand if that file does not contain any lines that contain "a".
No matter what pattern you are searching for, grep -FL patternfile... will always list every file operand that names an empty file and grep -Flv patternfile... will never list any file operand that names an empty file.
These 2 Users Gave Thanks to Don Cragun For This Post:
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)
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)
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)
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)
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)
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)
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)
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)