| Newsgroups |
gmane.editors.sed.user |
| Message-ID |
<[email protected]> |
That was a great question.
As in previous response, if the file is totally empty, sed tries to read the first line, fails, and exits.
If the file has one line, but no EOL marker, sed reads the line, but somehow figures out NOT to an EOL marker when it outputs the pattern space.
Here is the normal case with EOL marker:
$ echo "X" | sed "s/X/Y/"
Y
$
Here is the case with EOL marker missing:
$ echo -n "X" | sed "s/X/Y/"
Y$
Are you wanting sed to take no action if no EOL marker on single line?
Daniel
---In [email protected], <dave_br@...> wrote:
On Fri, 14 Feb 2014 06:05:12 -0500 (EST), Jude DaShiell
<jdashiel@... mailto:jdashiel@...> wrote:
> Is it within sed's logical capacity to check a file and only do a command
> on that file if it has at least one line of text in it? For what I'm
> trying to do with a script, if the file has zero lines it should not have
> anything done to it.
If a file has zero lines sed can't do anything on it anyway, since by
definition sed works on input lines.
$ touch a
$ sed 's/^/foobar/' a
$
Pleae note that a file that is NOT 0 bytes in size is neither an empty file
nor one with no lines of text.
--
D.