Category: Install gnu sed on mac

By using our site, you acknowledge that you have read and understand our Cookie PolicyPrivacy Policyand our Terms of Service. It only takes a minute to sign up. I am using oh my zsh. I am not able to use some commands which I could do on ubuntu for e. I installed home-brew and then brew install gnu-sed --default-names but still I am unable to used sed command.

What should I do so that I can use all gnu commands without hassle on my Mac? Also please give me the list of commands on which I have to use gnu command instead of default for e. Note that the shell may have cached the location of the sed command already if you have used the command on the command line previously in the same shell session.

You may then use rehash in zsh to clear that cache, or open a new terminal. When a system provides a native sed implementation that is not GNU sedthen it is often better to install GNU sed as gsed to not break existing scripts relying on behaviour specific to the native sed.

Sign up to join this community.

install gnu sed on mac

The best answers are voted up and rise to the top. Home Questions Tags Users Unanswered. Asked 2 years, 7 months ago. Active 3 months ago. Viewed 9k times. Gilles 'SO- stop being evil' k gold badges silver badges bronze badges. Ishan Srivastava Ishan Srivastava 1 1 silver badge 5 5 bronze badges. Related: stackoverflow.

Active Oldest Votes. I added to the path. Still i would have liked to use gsed instead of changing what my actual sed did. IshanSrivastava Some info here: rkulla. Sign up or log in Sign up using Google. Sign up using Facebook.

Installing via Package Managers

Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Featured on Meta. Community and Moderator guidelines for escalating issues via new response….

Feedback on Q2 Community Roadmap. Related 9. Hot Network Questions. Question feed.By using our site, you acknowledge that you have read and understand our Cookie PolicyPrivacy Policyand our Terms of Service. Ask Different is a question and answer site for power users of Apple hardware and software. It only takes a minute to sign up. I am trying to install GNU sed.

Following this post I did. A priori it went fine, but then the command gsed is not found. First, let's check that it installed. Try brew list and you will get a list of installed formulae. If gnu-sed is in there then it installed okay. If it's not, then run brew install gnu-sed again and you should be okay. If it is in the list then try linking it and see what output you get. It should link okay and you will be off and running.

Sign up to join this community. The best answers are voted up and rise to the top. Home Questions Tags Users Unanswered. How to install GNU-sed? Ask Question. Asked 3 years, 8 months ago. Active 3 years, 8 months ago. Viewed 9k times. Following this post I did brew install gnu-sed A priori it went fine, but then the command gsed is not found. Try using find to find it. That said, depending on which is in your PATH first is the one that going to run if you don't do something to differentiate the two.

Maybe call the GNU version gsed. Do I just have to rename the file sed to gsed to rename the command? The filename and the command name are essentially the same thing, so you can rename the file or not, that's up to you. You could also just leave the file where it is and create a symlink to it, named however you want. If you don't understand what I'm saying, then you need to do some Googling.

Active Oldest Votes. Tony Williams Tony Williams 9, 1 1 gold badge 15 15 silver badges 46 46 bronze badges. I did as you said. However the commands gnu-sed and gsed are still not found and I don't think the sed command has been replaced.

All other bash commands work fine though. Your ln command therefore returns No such file or directory.By using our site, you acknowledge that you have read and understand our Cookie PolicyPrivacy Policyand our Terms of Service. Ask Different is a question and answer site for power users of Apple hardware and software. It only takes a minute to sign up. I know you said fsed however I could not find it anywhere so assuming it's a typo and you actually meant sed you can install it with:.

Sign up to join this community. The best answers are voted up and rise to the top. Home Questions Tags Users Unanswered. Ask Question. Asked 4 years, 9 months ago. Active 4 years, 9 months ago. Viewed 1k times. Scott C Wilson.

Subscribe to RSS

Did you mean that or sed? Or did you mean fuse? You are correct that the typo is more likely to be from "sed" but it could be something else, including "fuse". I just properly wrote GNU in upper case in my previous comment to you. I seriously doubt the OP meant fuse!

Active Oldest Votes. I know you said fsed however I could not find it anywhere so assuming it's a typo and you actually meant sed you can install it with: brew install gnu-sed Or brew install gnu-sed --with-default-names. You might also want to say that sed is already installed and that the OS X one is almost certainly good enough since sed is so old that any differences between the BSD sed installed and GNU sed will be minor, if any.

TonyWilliams, for a concrete case of a difference that mattered, see stackoverflow. Portability does not require the installation of a newer version of software or a different package of the same name. I think that this is Tony's point. Those of us that install different version of the same programs found in OS X do it for good reasons, were not just doing it because it can be done. The Overflow Blog. Featured on Meta. Community and Moderator guidelines for escalating issues via new response….

Feedback on Q2 Community Roadmap. Linked 4. Related Hot Network Questions. Question feed. Ask Different works best with JavaScript enabled.If you are a hard-core Linux user who just bought a shiny new Mac machine, you are going to have a big surprise realizing that not every command line skill you acquired over the years will be directly applicable in a Mac Terminal. Take for example the humble and useful sed editor, invaluable when you need to modify on the fly a bunch of text files.

You probably assume you could just fire up a Terminal and get your work done. On the other hand Linux uses the GNU version of these command line tools. Small but subtle differences have accumulated over the years.

In Linux I could write this in a console:. Look what my Mac has to say about this:. You have two solutions: first RTFM which in a polite form means read the man page, or you could cheat and install GNU sed from sources.

There is obviously a third solution to write a small and portable script in your preferred poison: Python, Ruby, Perl - all of them already installed on your machine.

install gnu sed on mac

Not mentioning that you could write a Bash script if you feel inclined. In the next part of this post I will assume that you have already installed Xcode on your system.

If you use Xcode 4. First you need to download the last stable version of sed, currently 4. Starting with GNU sed on Mac OSX Posted on March 7, by Paul If you are a hard-core Linux user who just bought a shiny new Mac machine, you are going to have a big surprise realizing that not every command line skill you acquired over the years will be directly applicable in a Mac Terminal.By using our site, you acknowledge that you have read and understand our Cookie PolicyPrivacy Policyand our Terms of Service.

The dark mode beta is finally here. Change your preferences any time. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. The -E flag means to use extended regular expressions. You should just use -eas on Linux. To match a 'tab'you need to put a real 'tab' in your script. This is easy in a file, harder in shell. Mac port provides a port for it sudo port install gsed. After installing it you can use gsed instead of sed. In addition to the answers above, you can exploit a useful but shell-dependent trick.

The following works on my Mac:. This trick might be useful in case you need the tab character specifically, without matching other whitespace i. For the above, the -e flag is not essential. This can be passed by sed character class [[:blank:]] that equal combination of space and tab character.

So you can try the following:. To get the exact output as you expected I used the following:. Learn more. Sed regex problem on Mac, works fine on Linux Ask Question. Asked 8 years, 9 months ago. Active 4 years, 4 months ago. Viewed 24k times. Any tips on how to solve this? Sample input: apa bepa psd cepa ; depa psd epa ; psd fepa gepa hepa ; For that input, the expected output is: apa bepa depa psd epa .By using our site, you acknowledge that you have read and understand our Cookie PolicyPrivacy Policyand our Terms of Service.

It only takes a minute to sign up. I have collaborators using Mac OS X. Currently, the script starts with! Another option would be to remove the GNUisms, but this may be a bit hard, as I do not have a Mac OS X install at hand and cannot ask my collaborators to test intermediate versions. Ultimately there either need to be changes to at least one of the environments, or changes to the script itself.

Giving an answer to my own question, or rather, an alternative approach that will work in this situation. A sed script ascript. This means that when on Mac OS X, one can call the script as gsed -f ascript. Sign up to join this community. The best answers are voted up and rise to the top. Home Questions Tags Users Unanswered.

Asked 6 years, 11 months ago. Active 6 years, 11 months ago. Viewed 5k times. Gilles 'SO- stop being evil' k gold badges silver badges bronze badges. I have no OS X to test this on, but wouldn't! That would make things much more portable and it is the reason why env always should be used rather than fixed paths.

Hennes: well, the problem is that on OS X, the sed I want would be called gsedbut your suggestion would work if the script does not contain any GNUisms. Active Oldest Votes.

There are a few options: Use! Chris Down Chris Down 93k 19 19 gold badges silver badges bronze badges. I don't think command -v is significantly more portable than type. Some old non-POSIX shells like variants of the Bourne shell, have type but not command -v though some older ones don't set the exit status to non-zero on command-not-found.

I once reported to the LSB that having neither was a problem, they acknowledged it, I though they did something about it, but now quickly looking at the latest spec, there doesn't seem to be any type or command command!? LSB now does mandate both type and command though I don't see that it says whether -v should be supported. So it looks like type is required by the LSB, but maybe not command -v. Sign up or log in Sign up using Google. Sign up using Facebook.

Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Featured on Meta. Community and Moderator guidelines for escalating issues via new response…. Feedback on Q2 Community Roadmap. Related Hot Network Questions. Question feed.By using our site, you acknowledge that you have read and understand our Cookie PolicyPrivacy Policyand our Terms of Service. It only takes a minute to sign up.

Currently I'm struggling with how to insert a line of text after a certain line number. Any ideas what's wrong here? Do I have a typo? Or am I not understanding another difference between versions of sed? This makes writing one-liners a bit of a pain, which is probably the reason for the following GNU extension to the aiand c commands:. This enables a simplification in scripting a one-line add.

This extension also works with the i and c commands. The easiest way is to just insert a quoted newline:. As described in this answerit's helpful when using sed commands like i and a to use multiple -e " Each of these clauses will be understood to be separated by newlines. The i and a commands are hard to use in inline sed scripts otherwise they're designed for use in a multiline sed script file invoked using sed -f file But you can use it to terminate the line of text that's to be appended. In this specific case, what you're trying to do might in fact be accomplished with a single -e You just have to use the a command correctly.

So you could do:.

install gnu sed on mac

If you're interested, the best way to do this is install it through Homebrew. Then when you run into a syntax issue with date or some other program you can just use the GNU version. Perl doesn't suffer from such platform dependent GNU vs. You could do:. The -n' option creates a loop that reads every line of the input file.

Unlike its cousin -p not used here it doesn't automatically print every line read. The -i invokes in-place replacement. The argument to -i viz. It leaves a backup of the unmodified file. The -e signals the beginning of the script.

Thus the command line reads 'file' and when the line-number equals 4, it prints that line followed by whatever you want to inject. I would hasten to add that Perl owes its roots to sedAWK and C, so the syntax for simple substitutions, etc. Sign up to join this community.

The best answers are voted up and rise to the top.


thoughts on “Install gnu sed on mac

Leave a Reply

Your email address will not be published. Required fields are marked *