3 ms·
I bet many of us do this due to small differences between BSD and GNU coreutils. One that always gets me is: sed -i '' 's/foo/bar/g' # BSD sed sed -i 's/f
by divbzero 3y ago
I bet many of us do this due to small differences between BSD and GNU coreutils. One that always gets me is:
sed -i '' 's/foo/bar/g' # BSD sed
sed -i 's/foo/bar/g' # GNU sed
- jorams 3y agoThat is indeed an incredibly frustrating difference, because there is no version of it that works on both GNU and macOS. In practice I often end up using perl to do an in-place search-replace instead.
- jcelerier 3y agoIt takes a second to install gnu coreutils with homebrew and make Macs barely useable
- emmelaich 3y agoOr just use Perl
- DonHopkins 3y agoAs long as you're using stone knives, might as well throw in some bear skins. https://www.youtube.com/watch?v=F226oWBHvvI https://www.youtube.com/watch?v=F226oWBHvvI
- emmelaich 3y agoFun! But honestly there's a place for Perl. There's far less variance between Perls on different systems than there are for sed/awk/shell. So if you want performant portable code, Perl does better than all of those. I'd never use Perl for a 'big' program these days but it still beats the crap out of the mess of sed/awk/bash/ksh/zsh.
- freedomben 3y agoApple has been threatening to remove perl for ages. One of these days they'll find the "courage" to do so and we'll need a better strategy.
- arp242 3y agoFreeBSD removed Perl from base ages ago, in FreeBSD 5 or 6. That went alright. I don't even have it on my Linux system any more; for better or worse, fewer and fewer things use it.
- dolni 3y agoI much prefer Linux but having used Macs a few times for work, I absolutely cannot recommend making GNU coreutils the default option on Macs. If you make GNU coreutils the first binaries in PATH, you can expect subtle, _very nasty_ issues. The last one I encountered was `hostname` taking something like 5 seconds to run. Before that, there was some bug with GNU’s stty which I don’t remember the specifics of.
- arp242 3y agoBut "sed -i'' s/../../ FILE" will work on both, no? Or -i.orig if you want to keep a backup file?
- jorams 3y agoThat does not work on macOS. "-i''" is the same as just a bare "-i", and it will then interpret the next argument as the backup suffix.
- arp242 3y agoOops yes, that should have been -i '' with a space. But I see now that GNU doesn't accept -i '', or even -i .orig. It MUST be without a space: "-i.orig". The reason for that I assume is there's no way to disambiguate: echo foo | sed -i pattern echo foo | sed -i .orig But you can still use "-i.orig"; that should work on both. That will leave you with a .orig file to clean up, but arguably that's not a bad thing as -i can clobber files.
- deleted 3y ago[deleted]