I ran into this problem about a month ago with a bash script that I was writing on my MacBook Pro. For some reason, sed in place editing with ‘sed -i
‘ just wouldn’t work, no matter what I did, and I couldn’t find any solution online.
When running something like
sed -i 's/before/after/' test.txt
you get the error message sed: 1: "test.txt": undefined label 'est.txt'
.
Eventually, it turned out to be because sed’s ‘-i
‘ option takes a parameter to indicate what extension to add to the file name when making a backup. For example,
sed -i '.bak' 's/before/after/' test.txt
leaves you with two files, ‘test.txt
‘ and ‘test.txt.bak
‘, where ‘test.txt.bak
‘ is the original version. Unlike Ubuntu and other linux versions, on OS X, this extension parameter is required. If you really know what you’re doing and don’t want a backup made, you need to provide an empty string ”.
The correct way to run this command on OSX is
sed -i '' 's/before/after/' test.txt
September 15, 2010 at 2:03 am
Thanks! I ran into this same issue. Your post helped!
September 15, 2010 at 10:33 am
Awesome! I’m glad you didn’t have to spend as much time as I did figuring it out!
November 12, 2010 at 2:55 am
Hey thanks..! Helped a lot
June 23, 2011 at 12:44 am
Thanks for sharing 😉
August 29, 2011 at 3:33 pm
another way is:
sed ‘s/before/after/’ -i — test.txt
September 23, 2011 at 5:01 am
Thanks! This thing was driving me nuts.
March 23, 2012 at 11:12 pm
This was a real help thanks.
November 23, 2013 at 8:36 pm
Great! You just saved me a good deal of searching and fiddling !!
November 28, 2013 at 12:24 pm
Le chef de la majorité démocrate du Sénat américain, Harry Reid, a annoncé plus t?t dans la journée qu’il avait conclu avec son homologue républicain un accord de sortie de crise pour relever le plafond de la dette. Leur compromis, annoncé dans l’hémicycle du Sénat, relèverait le plafond de la dette et rouvrirait immédiatement les agences fédérales partiellement fermées depuis le 1er octobre, tout en convoquant une commission pour négocier un budget pour 2014.
[url=http://www.firminyvolleyball.com/css/canadagoose-fr.php]canada goose pas cher[/url]
canada goose pas cher
November 28, 2013 at 12:25 pm
Le livret?A est une épargne solidaire. Le pécule des épargnants est faiblement rémunéré mais cet argent est ensuite prêté?aux organismes?HLM?pour la construction de logements sociaux à des taux d’intérêt très faibles et sur le temps long. Ce système, qui fonctionne depuis des dizaines d’années, a fait des jaloux?: les banques. Elles lorgnent sur les milliards réservés à la solidarité et ont fait pression sur les gouvernements successifs pour obtenir une part du g?teau.
[url=http://www.seniorhandihabitat.fr/lancelpascher-fr.php]sac lancel[/url]
sac lancel
November 28, 2013 at 12:26 pm
Ce médecin, très “choqué” par l’affaire de l’h?pital de Bayonne, rappelle par ailleurs qu’il existe un réseau local –Palliadour– spécialisé dans les soins palliatifs et toujours disponible pour, avec un médecin référant, assister un médecin placé devant une “situation de fin de vie difficile”.
[url=http://www.agenceneptune.com/FR/Abercrombie/]http://www.agenceneptune.com/FR/Abercrombie/[/url]
http://www.agenceneptune.com/FR/Abercrombie/
November 29, 2013 at 7:37 am
thank you thank you thank you
December 20, 2013 at 8:27 pm
Thanks for this post, saved me some trouble. 🙂
October 25, 2015 at 10:16 am
[…] the ” is for the undefined error in MAC: https://mpdaugherty.wordpress.com/2010/05/27/difference-with-sed-in-place-editing-on-mac-os-x-vs-linu… […]