|
|
#1 |
|
Prospect
Join Date: Oct 2008
Location: Leominster, Massachusetts
Posts: 48
|
sed with -i switch not working in OSX Leopard
I'm new to OSX Leopard and Macs in general, but I've used sed for years. I'm trying to run the following sed script:
sed -i 's/^[[:space:]]\{11\}//g' menu1a.sh This is the error message I get. sed: 1: "menu1a.sh": invalid command code m If I run this script without the -i switch, the script works as expected. Also, if I run it in an ssh window in Linux, the -i switch version also works. Does anyone have any ideas on what the problem is? Any advice would be greatly appreciated. peterv6 |
|
|
|
|
|
#2 | |||||||||||||||||||||||
|
Site Admin
Join Date: Jan 2002
Location: Montreal
Posts: 31,941
|
The sed manpage on Leopard has the following synopsis:
which seems to indicate that if you want to use the "-i" option, you need to supply the command using the "-e" option. Sed, like many other Unix tools is not necessarily exactly the same across different versions of Unix. The Leopard version of all Unix tools are supposed to adhere to the Open Brand UNIX 03 specifications (SUSv3 and POSIX 1003.1). It is quite likely that the previous versions of Unix you have used did not conform to this standard.
__________________
hayne.net/macosx.html Last edited by hayne; 10-24-2008 at 06:02 PM. |
|||||||||||||||||||||||
|
|
|
|
|
#3 |
|
MVP
Join Date: Jun 2007
Location: Skellefteċ, Sweden
Posts: 1,173
|
__________________
/Bengt-Arne Fjellner IT-Administrator Luleċ university, Sweden. Some say: "You learn as long as you live". My way: "You live as long as you learn". |
|
|
|
|
|
#4 | |||||||||||||||||||||||
|
Hall of Famer
Join Date: Apr 2002
Posts: 3,315
|
Seems like Linux is being far too generous. -i 's/^[[:space:]]\{11\}//g' <-- makes it look like "s/^[[:space:]]\{11\}//g" is the extension given to "-i" baf's quotes serve to clarify to the interpreter (and to humans reading it) that there is no extension. hayne's -e is also a means with which to disambiguate. Thus, these all work: sed -i "" 's/^[[:space:]]\{11\}//g' menu1a.sh sed -i -e 's/^[[:space:]]\{11\}//g' menu1a.sh sed -ie 's/^[[:space:]]\{11\}//g' menu1a.sh sed -i "" -e 's/^[[:space:]]\{11\}//g' menu1a.sh Makes sense. |
|||||||||||||||||||||||
|
|
|
|
|
#5 |
|
Prospect
Join Date: Oct 2008
Location: Leominster, Massachusetts
Posts: 48
|
Hal, Hayne, & Baf, thank you all. I worked in a Linux shop (Ubuntu), which as Hal noted must be a little "generous".
Also a big Thanks! to BAF for including his link to the post explaining the differences in sed between systems. I'll remember to check the man pages from now on! jt6 |
|
|
|
|
|
#6 |
|
Prospect
Join Date: Oct 2008
Location: Leominster, Massachusetts
Posts: 48
|
BAF, one question, when you say system sed manual, what exactly are you referring to? I know what man pages are, but "system sed manual" I'm unfamiliar with.
Thanks again.... |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|