Problem with sed
Ruben Schade
newsgroups at rubenschade.com
Wed May 20 05:53:11 UTC 2015
On Mon, 18 May 2015, at 23:31, Matthew Seaman wrote:
> On 2015/05/18 14:00, Jerry wrote:
> > I rarely use sed, so I admit to not being fully acquainted with its
> > idiosyncrasies,; however, this one is really annoying.
> >
> > I am using this command in an attempt to remove empty lines:
> >
> > $ sed -i /^$/d /var/tmp/myfile.txt
> >
> > and get this error:
> >
> > sed: 1: "/var/tmp/myfile.txt": undefined label 'mp/myfile.txt'
> >
> > I don't understand why. I am following the example I found in the "sed & awk" handbook by "O'Reilly"
> >
>
> sed -i.bak -e '/^$/d' /var/tmp/myfile.txt
>
> You're getting sed(1) confused as to what is the extension for the
> backup of the file it creates, what the command you want to rn is and
> what the input filename is. Also, you need to put some characters of
> syntactic significance to the shell inside quote marks.
>
> Cheers,
>
> Matthew
>
>
> Email had 1 attachment:
> + signature.asc
> 1k (application/pgp-signature)
Part the confusion may lie in the difference between GNU and BSD
userland sed, which I'll admit has bitten me a few times.
GNU sed will accept -i (without an argument) as in-line edit to the
original file. For BSD sed, you need an empty string (-i '').
--
Cheers,
Ruben Schade
More information about the freebsd-questions
mailing list