0

I am having trouble making sed work on my mac terminal. The original version I have is /usr/bin/sed I want to see what version it is so I type:

sed --version 

I get the following output:

/usr/bin/sed: illegal option -- - usage: sed script [-Ealn] [-i extension] [file ...] sed [-Ealn] [-i extension] [-e script] ... [-f script_file] ... [file ...]

My man page is for sed 4.2 and that should have a --version option

I then installed to /usr/local/bin by downloading from gnu ftp http://ftp.gnu.org/gnu/sed/

I then run /usr/local/bin/sed --version and still get same output as with original version. I am completely confused, can anyone figure out what I am doing wrong?

EDIT: It seems like even though which sed gives me /usr/local/bin/sed the command sed is still running /usr/bin/sed, consequently /usr/local/bin/sed is not being invoked. If I invoke with full path it works as expected.

I guess question is now why which sed is giving me /usr/local/bin/sed yet the command run when I type sed is /usr/bin/sed

1 Answer 1

2

Your /usr/bin/sed is the BSD sed which does not support --version as your error statement shows. The man page for it is /usr/share/man/man1/sed.1.gz, when I read that there is no mention of a version at all, however the date on the man page is May 10, 2005.

I am thinking you have an incorrect man page. Most probably a MANPATH that is looking somewhere else first.

As for why /usr/local/bin/sed which you are saying is GNU sed does not honor the --version I am not sure about. Can you give more detail about this?

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks Timothy. I have just rebooted my computer and it now works properly. I did not know about the BSD sed default for MAC so thanks. I think when I installed GNU Sed I corrupted something.
@mcheema: The --version and --help options are for GNU programs that use GNU getopt_long() to process options. They are almost universal in programs that do use getopt_long(). They are not supported in that form by programs using plain getopt() — which covers many programs not written to the GNU coding standards. Sometimes, programs accept -V (or -v) to print version information; sometimes, programs accept -h or -? to print help. However, there's no compulsion to do so and many don't.
thanks @Jonathan Leffler. I am mostly an R programmer but have recently been inspired to dust of awk and sed after reading a Brian Kernighan interview as in many use cases of dealing with messy data I find these tools pretty useful.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.