Quantcast
Channel: sed in-place flag that works both on Mac (BSD) and Linux - Stack Overflow
Browsing all 16 articles
Browse latest View live

Answer by David Ongaro for sed in-place flag that works both on Mac (BSD) and...

The problem is that sed is a stream editor, therefore in-place editing is a non-POSIX extension and everybody may implement it differently. That means for in-place editing you should use ed for best...

View Article


Answer by Jon for sed in-place flag that works both on Mac (BSD) and Linux

Portable script for both GNU systems and OSX:if [[ $(uname) == "Darwin" ]]; then SP=" " # Needed for portability with sedfised -i${SP}'' -e "s/foo/bar/g" -e "s/ping/pong/g" foobar.txt

View Article

Answer by nwinkler for sed in-place flag that works both on Mac (BSD) and Linux

Here's another version that works on Linux and macOS without using eval and without having to delete backup files. It uses Bash arrays for storing the sed parameters, which is cleaner than using eval:#...

View Article

Answer by sdaau for sed in-place flag that works both on Mac (BSD) and Linux

If you need to do sed in-place in a bash script, and you do NOT want the in-place to result with .bkp files, and you have a way to detect the os (say, using ostype.sh), -- then the following hack with...

View Article

Answer by vikrantt for sed in-place flag that works both on Mac (BSD) and Linux

I ran into this problem. The only quick solution was to replace the sed in mac to the gnu version:brew install gnu-sed

View Article


Answer by Zombo for sed in-place flag that works both on Mac (BSD) and Linux

The -i option is not part of POSIX Sed. A more portable method would beto use Vim in Ex mode:ex -sc '%s/alfa/bravo/|x' file% select all liness replacex save and close

View Article

Answer by David G for sed in-place flag that works both on Mac (BSD) and Linux

The following works for me on Linux and OS X:sed -i''<expr> <file>e.g. for a file f containing aaabbaabased -i'''s/b/c/g' fyields aaaccaaca on both Linux and Mac. Note there is a quoted...

View Article

Answer by Lewy for sed in-place flag that works both on Mac (BSD) and Linux

When on OSX, I always install GNU sed version via Homebrew, to avoid problems in scripts, because most scripts were written for GNU sed versions.brew install gnu-sed --with-default-namesThen your BSD...

View Article


Answer by Alex Dupuy for sed in-place flag that works both on Mac (BSD) and...

As Noufal Ibrahim asks, why can't you use Perl? Any Mac will have Perl, and there are very few Linux or BSD distributions that don't include some version of Perl in the base system. One of the only...

View Article


Answer by kine for sed in-place flag that works both on Mac (BSD) and Linux

If you really want to just use sed -i the 'easy' way, the following DOES work on both GNU and BSD/Mac sed:sed -i.bak 's/foo/bar/' filenameNote the lack of space and the dot.Proof:# GNU sed% sed...

View Article

Answer by Guillermo for sed in-place flag that works both on Mac (BSD) and Linux

You can use sponge. Sponge is an old unix program, found in moreutils package (both in ubuntu and probably debian, and in homebrew in mac). It will buffer all the content from the pipe, wait until the...

View Article

Answer by analogue for sed in-place flag that works both on Mac (BSD) and Linux

There is no way to have it working.One way is to use a temporary file like:TMP_FILE=`mktemp /tmp/config.XXXXXXXXXX`sed -e "s/abc/def/" some/file > $TMP_FILEmv $TMP_FILE some/fileThis works on both

View Article

Answer by Big Rich for sed in-place flag that works both on Mac (BSD) and Linux

Steve Powell's answer is quite correct, consulting the MAN page for sed on OSX and Linux (Ubuntu 12.04) highlights the in-compatibility within 'in-place' sed usage across the two operating...

View Article


Answer by Steve Powell for sed in-place flag that works both on Mac (BSD) and...

Answer: No.The originally accepted answer actually doesn't do what is requested (as noted in the comments). (I found this answer when looking for the reason a file-e was appearing "randomly" in my...

View Article

Answer by dnadlinger for sed in-place flag that works both on Mac (BSD) and...

This works with GNU sed, but not on OS X:sed -i -e 's/foo/bar/' target.filesed -i'' -e 's/foo/bar/' target.fileThis works on OS X, but not with GNU sed:sed -i '' -e 's/foo/bar/' target.fileOn OS X you...

View Article


sed in-place flag that works both on Mac (BSD) and Linux

Is there an invocation of sed todo in-place editing without backups that works both on Linux and Mac? While the BSD sed shipped with OS X seems to need sed -i ''…, the GNU sed Linux distributions...

View Article
Browsing all 16 articles
Browse latest View live




<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>