Unix Shell - sed: illegal option -- r when running bibexport.sh

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > October 2006 > sed: illegal option -- r when running bibexport.sh





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author sed: illegal option -- r when running bibexport.sh
beatnick

2006-10-29, 7:22 pm

Hi, I'm trying to run bibexport.sh on a LaTeX aux file to produce a
subsetted .bib file. But when I run ./bibexport.sh it gets as far as
creating the new .bib file but doesn't write anything to it. Instead I
get the error:

sed: illegal option -- r
usage: sed script [-Ean] [-i extension] [file ...]
sed [-an] [-i extension] [-e script] ... [-f script_file] ...
[file ...]


Can anyone tell me what I'm doing wrong? I've read the user guide,
searched the web etc, am stumped.

Many thanks in advance,

Nick

Chris F.A. Johnson

2006-10-29, 7:22 pm

On 2006-10-29, beatnick wrote:
> Hi, I'm trying to run bibexport.sh on a LaTeX aux file to produce a
> subsetted .bib file. But when I run ./bibexport.sh it gets as far as
> creating the new .bib file but doesn't write anything to it. Instead I
> get the error:
>
> sed: illegal option -- r
> usage: sed script [-Ean] [-i extension] [file ...]
> sed [-an] [-i extension] [-e script] ... [-f script_file] ...
> [file ...]
>
>
> Can anyone tell me what I'm doing wrong? I've read the user guide,
> searched the web etc, am stumped.


You are not doing anything wrong; bibexport.sh is using a
non-standard (GNU only?) option to sed. The guide should have
mentioned that.

--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
beatnick

2006-10-29, 7:22 pm


Chris F.A. Johnson wrote:

>
> You are not doing anything wrong; bibexport.sh is using a
> non-standard (GNU only?) option to sed. The guide should have
> mentioned that.
>

hmm, i see. So whats the easiest way to make this work? Bearing in mind
that my knowledge of Unix is minimal...

Chris F.A. Johnson

2006-10-29, 7:22 pm

On 2006-10-29, beatnick wrote:
>
> Chris F.A. Johnson wrote:
>
> hmm, i see. So whats the easiest way to make this work? Bearing in mind
> that my knowledge of Unix is minimal...


Replace sed with egrep (or grep -E):

Change:

sed -r -e \
"/^ *[cC][rR][oO][sS][sS][rR][eE][fF] *= *[^,]+,?$/d" \
${TMPFILE}.bbl >> ${FINALFILE};


To (untested):

grep -E -v '^ *[cC][rR][oO][sS][sS][rR][eE][fF] *= *[^,]+,?$' \
${TMPFILE}.bbl >> ${FINALFILE};

--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
Peter Flynn

2006-10-29, 7:22 pm

beatnick wrote:
> Hi, I'm trying to run bibexport.sh on a LaTeX aux file to produce a
> subsetted .bib file. But when I run ./bibexport.sh it gets as far as
> creating the new .bib file but doesn't write anything to it. Instead I
> get the error:
>
> sed: illegal option -- r
> usage: sed script [-Ean] [-i extension] [file ...]
> sed [-an] [-i extension] [-e script] ... [-f script_file] ...
> [file ...]
>
>
> Can anyone tell me what I'm doing wrong? I've read the user guide,
> searched the web etc, am stumped.


Isn't -r a GNU extension to sed or something? And you're using a
Sun or a Mac perhaps?

The offending line seems to be

sed -r -e \
"/^ *[cC][rR][oO][sS][sS][rR][eE][fF] *= *[^,]+,?$/d" \
${TMPFILE}.bbl >> ${FINALFILE};

I'm not enough of an RE hacker to know if that really requires -r
or not: try removing the -r and see if it works.

///Peter
Harald Hanche-Olsen

2006-10-30, 7:22 am

+ "Chris F.A. Johnson" <cfajohnson@gmail.com>:

| grep -E -v '^ *[cC][rR][oO][sS][sS][rR][eE][fF] *= *[^,]+,?$' \
| ${TMPFILE}.bbl >> ${FINALFILE};

which you ought to be able to simplify into

egrep -iv '^ *crossref *= *[^,]+,?$' \
${TMPFILE}.bbl >> ${FINALFILE};

AFAICT, the sed command that started the thread needed the GNU
specific -r option because sed regular expressions don't normally
support the special character `+'. But the grep ones do, hence no
need to use egrep. But doing so doesn't hurt, and it may be better to
leave it in just in case I'm wrong and some grep out there doesn't
support `+'.

--
* Harald Hanche-Olsen <URL:http://www.math.ntnu.no/~hanche/>
- It is undesirable to believe a proposition
when there is no ground whatsoever for supposing it is true.
-- Bertrand Russell
Bruce Barnett

2006-10-30, 7:22 am

Harald Hanche-Olsen <hanche@math.ntnu.no> writes:

> AFAICT, the sed command that started the thread needed the GNU
> specific -r option because sed regular expressions don't normally
> support the special character `+'. But the grep ones do, hence no
> need to use egrep.


.....if your grep supports "+"

But if they are not using GNU sed, then what are the odds that grep
uses "+"?

--
Sending unsolicited commercial e-mail to this account incurs a fee of
$500 per message, and acknowledges the legality of this contract.
Robin Fairbairns

2006-10-30, 7:22 am

"Chris F.A. Johnson" <cfajohnson@gmail.com> writes:
>On 2006-10-29, beatnick wrote:
>
> Replace sed with egrep (or grep -E):
>
> Change:
>
> sed -r -e \
> "/^ *[cC][rR][oO][sS][sS][rR][eE][fF] *= *[^,]+,?$/d" \
> ${TMPFILE}.bbl >> ${FINALFILE};
>
>
> To (untested):
>
>grep -E -v '^ *[cC][rR][oO][sS][sS][rR][eE][fF] *= *[^,]+,?$' \
> ${TMPFILE}.bbl >> ${FINALFILE};


this is one of nicolas markey's packages: nicolas, are you listening?
-- it would be good to update, i suspect.
--
Robin Fairbairns, Cambridge
beatnick

2006-10-30, 1:19 pm

Hi to all again - tried to post my thanks earlier but somehow it got
lost. Anyhow, I followed the egrep suggestion and the script ran
perfectly, so many thanks to you all.

And in answer to one of the earlier comments, yes, I'm running this on
a Mac...

regards,

Nick

Harald Hanche-Olsen

2006-10-30, 1:19 pm

+ Bruce Barnett <spamhater113+U061030065017@grymoire.com>:

| Harald Hanche-Olsen <hanche@math.ntnu.no> writes:
|
|> AFAICT, the sed command that started the thread needed the GNU
|> specific -r option because sed regular expressions don't normally
|> support the special character `+'. But the grep ones do, hence no
|> need to use egrep.
|
| ....if your grep supports "+"
|
| But if they are not using GNU sed, then what are the odds that grep
| uses "+"?

Uh, thin. I was reading the man page for the SunOS grep too hastily;
it mentions +, but only in connection with the -E flag, which fact
eluded me. Mea culpa. Egrep it is, then. (But surely, using sed
where grep will do makes very little sense.)

--
* Harald Hanche-Olsen <URL:http://www.math.ntnu.no/~hanche/>
- It is undesirable to believe a proposition
when there is no ground whatsoever for supposing it is true.
-- Bertrand Russell
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com