Rocksolid Light

Welcome to Rocksolid Light

mail  files  register  newsreader  groups  login

Message-ID:  

"Protozoa are small, and bacteria are small, but viruses are smaller than the both put together."


devel / comp.unix.shell / Re: Get a list of files that contain a string

SubjectAuthor
* Get a list of files that contain a stringMarco Moock
+- Get a list of files that contain a stringChristian Weisgerber
+* Get a list of files that contain a stringChris Elvidge
|+* Get a list of files that contain a stringJanis Papanagnou
||`* Get a list of files that contain a stringMarco Moock
|| `- Get a list of files that contain a stringJanis Papanagnou
|`- Get a list of files that contain a stringMarco Moock
+* Get a list of files that contain a stringJanis Papanagnou
|`* Get a list of files that contain a stringSpiros Bousbouras
| `- Get a list of files that contain a stringJanis Papanagnou
`- Get a list of files that contain a stringEd Morton

1
Get a list of files that contain a string

<ueukos$2g61s$4@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=7425&group=comp.unix.shell#7425

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: mm+usenet-es@dorfdsl.de (Marco Moock)
Newsgroups: comp.unix.shell
Subject: Get a list of files that contain a string
Date: Tue, 26 Sep 2023 15:02:19 +0200
Organization: A noiseless patient Spider
Lines: 14
Message-ID: <ueukos$2g61s$4@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 26 Sep 2023 13:02:20 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="2fff20e4d4f9d1b7312ed0e88b6a40ff";
logging-data="2627644"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18nVL+8NaRtLY9lLRVpKp/0"
Cancel-Lock: sha1:ZG9FdQeKBOujdyKowFUjFO8AYIc=
 by: Marco Moock - Tue, 26 Sep 2023 13:02 UTC

Hello!

What is the best way to get a list of files that contain a specific
string without printing the content?

I can use find to select all files in a directory including subdirs and
I can use grep to filter it, but it prints the content.

Is there a better solution for that?

--
kind regards
Marco

Re: Get a list of files that contain a string

<slrnuh5mea.1h0e.naddy@lorvorc.mips.inka.de>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=7426&group=comp.unix.shell#7426

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!news.swapon.de!news.mixmin.net!news2.arglkargh.de!news.karotte.org!news.szaf.org!inka.de!mips.inka.de!.POSTED.localhost!not-for-mail
From: naddy@mips.inka.de (Christian Weisgerber)
Newsgroups: comp.unix.shell
Subject: Re: Get a list of files that contain a string
Date: Tue, 26 Sep 2023 13:16:58 -0000 (UTC)
Message-ID: <slrnuh5mea.1h0e.naddy@lorvorc.mips.inka.de>
References: <ueukos$2g61s$4@dont-email.me>
Injection-Date: Tue, 26 Sep 2023 13:16:58 -0000 (UTC)
Injection-Info: lorvorc.mips.inka.de; posting-host="localhost:::1";
logging-data="50191"; mail-complaints-to="usenet@mips.inka.de"
User-Agent: slrn/1.0.3 (FreeBSD)
 by: Christian Weisgerber - Tue, 26 Sep 2023 13:16 UTC

On 2023-09-26, Marco Moock <mm+usenet-es@dorfdsl.de> wrote:

> What is the best way to get a list of files that contain a specific
> string without printing the content?

grep -l

--
Christian "naddy" Weisgerber naddy@mips.inka.de

Re: Get a list of files that contain a string

<ueuqrk$2i2b8$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=7427&group=comp.unix.shell#7427

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!rocksolid2!news.neodome.net!news.mixmin.net!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris@mshome.net (Chris Elvidge)
Newsgroups: comp.unix.shell
Subject: Re: Get a list of files that contain a string
Date: Tue, 26 Sep 2023 15:46:10 +0100
Organization: A noiseless patient Spider
Lines: 18
Message-ID: <ueuqrk$2i2b8$1@dont-email.me>
References: <ueukos$2g61s$4@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 26 Sep 2023 14:46:12 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="b30b409de85f1d95f60a11b7478d4d3f";
logging-data="2689384"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX184+c/XxiYMJZmOYExem7nzlzChACtKmVs="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101
Thunderbird/52.2.1 Lightning/5.4
Cancel-Lock: sha1:D7TcEX27wGkdVA26/H0SEXp8mf4=
Content-Language: en-GB
In-Reply-To: <ueukos$2g61s$4@dont-email.me>
 by: Chris Elvidge - Tue, 26 Sep 2023 14:46 UTC

On 26/09/2023 14:02, Marco Moock wrote:
> Hello!
>
> What is the best way to get a list of files that contain a specific
> string without printing the content?
>
> I can use find to select all files in a directory including subdirs and
> I can use grep to filter it, but it prints the content.
>
> Is there a better solution for that?
>

Forget find, use grep -rl (or -Rl) (recursive, list)

--
Chris Elvidge, England
A TRAINED APE COULD NOT TEACH GYM

Re: Get a list of files that contain a string

<ueuras$2i59c$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=7428&group=comp.unix.shell#7428

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: janis_papanagnou+ng@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: Get a list of files that contain a string
Date: Tue, 26 Sep 2023 16:54:19 +0200
Organization: A noiseless patient Spider
Lines: 29
Message-ID: <ueuras$2i59c$1@dont-email.me>
References: <ueukos$2g61s$4@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 26 Sep 2023 14:54:20 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="9ed2156370a77fd1faf2578b87920003";
logging-data="2692396"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX184Rs5AQTQ/ajGjAAblUBIc"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:IbWDrvbHwJteAUZmuUFlLtcrK00=
X-Enigmail-Draft-Status: N1110
In-Reply-To: <ueukos$2g61s$4@dont-email.me>
 by: Janis Papanagnou - Tue, 26 Sep 2023 14:54 UTC

On 26.09.2023 15:02, Marco Moock wrote:
> Hello!
>
> What is the best way to get a list of files that contain a specific
> string without printing the content?
>
> I can use find to select all files in a directory including subdirs and
> I can use grep to filter it, but it prints the content.
>
> Is there a better solution for that?

If you don't need to "find" the files it's just

grep -lF specific-string ...list-of-files-and-or-file-patterns...

or if you have to find the files

find ...file-properties... | xargs grep -lF specific-string

It it's not a "specific string" but a regular expression pattern that
you want to match in the files then omit grep's F option, use just -l.

If filenames contain blanks and whatnot, add option -print0 to find
and -0 (this is a 'dash zero') to xargs.

Alternatively you may also use find's -exec option instead of xargs.

Janis

Re: Get a list of files that contain a string

<ueurha$2i6ij$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=7429&group=comp.unix.shell#7429

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: janis_papanagnou+ng@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: Get a list of files that contain a string
Date: Tue, 26 Sep 2023 16:57:45 +0200
Organization: A noiseless patient Spider
Lines: 8
Message-ID: <ueurha$2i6ij$1@dont-email.me>
References: <ueukos$2g61s$4@dont-email.me> <ueuqrk$2i2b8$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 26 Sep 2023 14:57:46 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="9ed2156370a77fd1faf2578b87920003";
logging-data="2693715"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+XqhR/EZedsMncaPLuY+W2"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:SgccYAJv5F5FLX6InOS7jYQFtZA=
In-Reply-To: <ueuqrk$2i2b8$1@dont-email.me>
 by: Janis Papanagnou - Tue, 26 Sep 2023 14:57 UTC

On 26.09.2023 16:46, Chris Elvidge wrote:
>
> Forget find, use grep -rl (or -Rl) (recursive, list)

Yes - ...in case your grep has it. (It's non-standard.)

Janis

Re: Get a list of files that contain a string

<uf0noe$2vpkl$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=7430&group=comp.unix.shell#7430

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: mm+usenet-es@dorfdsl.de (Marco Moock)
Newsgroups: comp.unix.shell
Subject: Re: Get a list of files that contain a string
Date: Wed, 27 Sep 2023 10:05:33 +0200
Organization: A noiseless patient Spider
Lines: 6
Message-ID: <uf0noe$2vpkl$1@dont-email.me>
References: <ueukos$2g61s$4@dont-email.me>
<ueuqrk$2i2b8$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 27 Sep 2023 08:05:34 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="4e7912673b34befb2984f4a614e1fef3";
logging-data="3139221"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19ffIdtpD1YtESXy1UIc6gc"
Cancel-Lock: sha1:nMkQBPW3aGaRXsqpfokb4GkcOOs=
 by: Marco Moock - Wed, 27 Sep 2023 08:05 UTC

Am 26.09.2023 um 15:46:10 Uhr schrieb Chris Elvidge:

> Forget find, use grep -rl (or -Rl) (recursive, list)

Thanks, that is fine.

Re: Get a list of files that contain a string

<uf0nqu$2vpkl$2@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=7431&group=comp.unix.shell#7431

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: mm+usenet-es@dorfdsl.de (Marco Moock)
Newsgroups: comp.unix.shell
Subject: Re: Get a list of files that contain a string
Date: Wed, 27 Sep 2023 10:06:53 +0200
Organization: A noiseless patient Spider
Lines: 13
Message-ID: <uf0nqu$2vpkl$2@dont-email.me>
References: <ueukos$2g61s$4@dont-email.me>
<ueuqrk$2i2b8$1@dont-email.me>
<ueurha$2i6ij$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 27 Sep 2023 08:06:54 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="4e7912673b34befb2984f4a614e1fef3";
logging-data="3139221"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+Hh/zP2psScHHXvYEUPawQ"
Cancel-Lock: sha1:AXuqcUfcsVlmQRfKxV9e9K9t7hE=
 by: Marco Moock - Wed, 27 Sep 2023 08:06 UTC

Am 26.09.2023 um 16:57:45 Uhr schrieb Janis Papanagnou:

> Yes - ...in case your grep has it. (It's non-standard.)

Mine has it.

grep 3.11-3 amd64 GNU grep, egrep and fgrep

OS is Debian.

Most Linux distributions ship GNU grep, some UNIX systems might have
other variants.

Re: Get a list of files that contain a string

<uf0o78$309p0$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=7432&group=comp.unix.shell#7432

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: janis_papanagnou+ng@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: Get a list of files that contain a string
Date: Wed, 27 Sep 2023 10:13:27 +0200
Organization: A noiseless patient Spider
Lines: 20
Message-ID: <uf0o78$309p0$1@dont-email.me>
References: <ueukos$2g61s$4@dont-email.me> <ueuqrk$2i2b8$1@dont-email.me>
<ueurha$2i6ij$1@dont-email.me> <uf0nqu$2vpkl$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 27 Sep 2023 08:13:28 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="68dbff0f845fd0821cc4f86884ca0699";
logging-data="3155744"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18KF+iaEqinCUMGx7ddSyqS"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:eXdNa/heebRYGcTDP5KGxB/9TpM=
In-Reply-To: <uf0nqu$2vpkl$2@dont-email.me>
 by: Janis Papanagnou - Wed, 27 Sep 2023 08:13 UTC

On 27.09.2023 10:06, Marco Moock wrote:
> Am 26.09.2023 um 16:57:45 Uhr schrieb Janis Papanagnou:
>
>> Yes - ...in case your grep has it. (It's non-standard.)
>
> Mine has it.

(Mine too.)

> [...]
>
> Most Linux distributions ship GNU grep, some UNIX systems might have
> other variants.

Sure, but in your OP you haven't told us in what environment you
are working or whether you have portability demands. So providing
a standard solution or pointing out non-standard ones is mandatory.

Janis

Re: Get a list of files that contain a string

<GjSRFyVAUJBJiRQJ4@bongo-ra.co>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=7433&group=comp.unix.shell#7433

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!news.hispagatos.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: spibou@gmail.com (Spiros Bousbouras)
Newsgroups: comp.unix.shell
Subject: Re: Get a list of files that contain a string
Date: Thu, 28 Sep 2023 04:42:49 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 15
Message-ID: <GjSRFyVAUJBJiRQJ4@bongo-ra.co>
References: <ueukos$2g61s$4@dont-email.me> <ueuras$2i59c$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 28 Sep 2023 04:42:49 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="72120b7779cf76260cf94ba1ad0cdc77";
logging-data="3725377"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/IOikRqXk48lpt5hocNsUH"
Cancel-Lock: sha1:IVdf/rgx8JxOqSipS3c5b+d+H5Q=
In-Reply-To: <ueuras$2i59c$1@dont-email.me>
X-Organisation: Weyland-Yutani
X-Server-Commands: nowebcancel
 by: Spiros Bousbouras - Thu, 28 Sep 2023 04:42 UTC

On Tue, 26 Sep 2023 16:54:19 +0200
Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
> or if you have to find the files
>
> find ...file-properties... | xargs grep -lF specific-string
>
> It it's not a "specific string" but a regular expression pattern that
> you want to match in the files then omit grep's F option, use just -l.
>
> If filenames contain blanks and whatnot, add option -print0 to find
> and -0 (this is a 'dash zero') to xargs.
>
> Alternatively you may also use find's -exec option instead of xargs.

I note that grep also has the -q option to not print output.

Re: Get a list of files that contain a string

<uf3huf$3kie1$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=7434&group=comp.unix.shell#7434

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!news.hispagatos.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: janis_papanagnou+ng@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: Get a list of files that contain a string
Date: Thu, 28 Sep 2023 11:44:46 +0200
Organization: A noiseless patient Spider
Lines: 12
Message-ID: <uf3huf$3kie1$1@dont-email.me>
References: <ueukos$2g61s$4@dont-email.me> <ueuras$2i59c$1@dont-email.me>
<GjSRFyVAUJBJiRQJ4@bongo-ra.co>
MIME-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 28 Sep 2023 09:44:47 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="32febf278a39c3f78dcd71db134af230";
logging-data="3819969"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19aAU5zMAJQWz67QTylw0LR"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:zve0HVFAXJRl2PEMPSP1Hu7dg3E=
In-Reply-To: <GjSRFyVAUJBJiRQJ4@bongo-ra.co>
 by: Janis Papanagnou - Thu, 28 Sep 2023 09:44 UTC

On 28.09.2023 06:42, Spiros Bousbouras wrote:
>
> I note that grep also has the -q option to not print output.

Yes, this is useful when you intend to use it as predicate

if grep -q ... ; then : found ; else : not found ; fi

and aren't interested in the output (the match or the file names).

Janis

Re: Get a list of files that contain a string

<ufbmq9$1hpjc$2@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=7436&group=comp.unix.shell#7436

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: mortonspam@gmail.com (Ed Morton)
Newsgroups: comp.unix.shell
Subject: Re: Get a list of files that contain a string
Date: Sun, 1 Oct 2023 06:56:58 -0500
Organization: A noiseless patient Spider
Lines: 25
Message-ID: <ufbmq9$1hpjc$2@dont-email.me>
References: <ueukos$2g61s$4@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 1 Oct 2023 11:56:58 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="e9bde01aafde9cfeef9c9c2cc50e33c7";
logging-data="1631852"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/MM8DscEH4d6opoNl3uNqm"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Cancel-Lock: sha1:xYMxg4d0+XQhClHqNA2f4hNDCfs=
X-Antivirus-Status: Clean
Content-Language: en-US
X-Antivirus: Avast (VPS 230930-4, 9/30/2023), Outbound message
In-Reply-To: <ueukos$2g61s$4@dont-email.me>
 by: Ed Morton - Sun, 1 Oct 2023 11:56 UTC

On 9/26/2023 8:02 AM, Marco Moock wrote:
> Hello!
>
> What is the best way to get a list of files that contain a specific
> string without printing the content?
>
> I can use find to select all files in a directory including subdirs and
> I can use grep to filter it, but it prints the content.
>
> Is there a better solution for that?
>

Use "find" to find files and "grep" to g/re/p (Globally match a Regular
Expression and Print) within files:

find . -type f -exec grep -Fl 'string' {} +

Note the `-F` to make it a string rather then regexp comparison.

The above will work on any Unix system as it's only using mandatory
POSIX tools/options.

Regards,

Ed.

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor