On 3/21/24 22:58, jack...@fastmail.com wrote:
> Paul Eggert wrote:
>> although doable it would be a bit of a pain to program
>
> yup - sure would be a pain.
>
> If you're not sure whether your actual input of interest will end
> in a newline, can you add one, to "feed grep's newline hunger",
> thus for instance replacing your example:
>
> grep -q foo <(sh -c 'printf foo ; sleep 30' &)
>
> with:
>
> grep -q foo <(sh -c 'printf foo ; echo ; sleep 30' &)
>
> In any case, grep is quite line oriented, as implied by an early
> sentence in the man page grep(1):
>
> "PATTERNS is one or more patterns separated by newline characters,"
>
This may not be helpful but I powered up and old old Sun server
running Solaris 8 where I see :
nix$ uname -a
SunOS nix 5.8 Generic_117350-62 sun4m sparc SUNW,SPARCstation-20
nix$ cat /etc/release
Solaris 8 2/04 s28s_hw4wos_05a SPARC
Copyright 2004 Sun Microsystems, Inc. All Rights Reserved.
Assembled 08 January 2004
nix$ which grep
/usr/xpg4/bin/grep
nix$ /usr/bin/printf "This is a line of text without a newline" | wc
0 9 40
nix$ /usr/bin/printf "This is a line of text without a newline" |
/usr/xpg4/bin/grep -c 'line'
1
nix$
So that seems to look at a "line" that is not a "line" as we see that wc
claims there are zero lines. The manpage[1] even claims the words :
"prints all lines that contain that pattern"
So I have to wonder. Old Solaris 8, once fully patched, was definately
compliant with SUSv2 which is all of POSIX.1b-1993, POSIX.1c-1996 as
well as ISO/IEC 9899 (C Standard) Amendment 1.
Anyways, this is just a crusty old grey beard here putting yet another
layer of paint onto the bikeshed ( https://www.bikeshed.com/ ) and I do
apologize for the messy paintwork.
--
Dennis Clarke
RISC-V/SPARC/PPC/ARM/CISC
UNIX and Linux spoken
[1] the man page on ye old old Solaris 8
nix$ man grep
Reformatting page. Please Wait... done
User Commands grep(1)
NAME
grep - search a file for a pattern
SYNOPSIS
/usr/bin/grep [ -bchilnsvw ] limited-regular-expression [
filename ... ]
/usr/xpg4/bin/grep [ -E | -F ] [ -c | -l | -q ] [
-bhinsvwx ] -e pattern_list ... [ -f pattern_file ] ...
[ file ... ]
/usr/xpg4/bin/grep [ -E | -F ] [ -c | -l | -q ] [
-bhinsvwx ] [ -e pattern_list ... ] -f pattern_file ... [
file ... ]
/usr/xpg4/bin/grep [ -E | -F ] [ -c | -l | -q ] [
-bhinsvwx ] pattern [ file ... ]
DESCRIPTION
The grep utility searches text files for a pattern and
prints all lines that contain that pattern. It uses a com-
pact non-deterministic algorithm.
Be careful using the characters $, *, [, ^, |, (, ), and \
in the pattern_list because they are also meaningful to the
shell. It is safest to enclose the entire pattern_list in
single quotes '... '.
If no files are specified, grep assumes standard input. Nor-
mally, each line found is copied to standard output. The
file name is printed before each line found if there is more
than one input file.
/usr/bin/grep
The /usr/bin/grep utility uses limited regular expressions
like those described on the regexp(5) manual page to match
the patterns.
/usr/xpg4/bin/grep
The options -E and -F affect the way /usr/xpg4/bin/grep
interprets pattern_list. If -E is specified,
/usr/xpg4/bin/grep interprets pattern_list as a full regular
expression (see -E for description). If -F is specified,
grep interprets pattern_list as a fixed string. If neither
are specified, grep interprets pattern_list as a basic regu-
lar expression as described on regex(5) manual page.
.
.
.