I need to install GNU grep on my Mac but I'm finding some difficulties.
I tried doing this:
brew install grep --with-default-names
But this is no longer an option since Homebrew removed --with-default-names.
Can anyone provide a solution for this?
Yes, --with-default-names was removed.
But some formulas, like grep, provided a workaround for this:
$ brew info grep
...
==> Caveats
All commands have been installed with the prefix "g".
If you need to use these commands with their normal names, you
can add a "gnubin" directory to your PATH from your bashrc like:
PATH="/usr/local/opt/grep/libexec/gnubin:$PATH"
...
First, to install, just do install without --with-default-names.
$ brew install grep
...
==> Summary
🍺 /usr/local/Cellar/grep/3.3: 21 files, 880.7KB
You should also see that same "Caveats" info I mentioned at the start. Now, by default, the Homebrew grep would be prefixed by a "g", so it's accessible as ggrep.
$ ggrep -V
ggrep (GNU grep) 3.3
Packaged by Homebrew
Copyright (C) 2018 Free Software Foundation, Inc.
...
This prevents it from shadowing the built-in grep that comes with Mac.
$ grep -V
grep (BSD grep) 2.5.1-FreeBSD
If you really need to use grep and not ggrep, just follow the instructions and put /usr/local/opt/grep/libexec/gnubin at the start of your PATH. You have to do this in your .bashrc or .bash_profile (whichever one you use).
$ echo 'export PATH="/usr/local/opt/grep/libexec/gnubin:$PATH"' >> ~/.bash_profile
$ source ~/.bash_profile
$ grep -V
grep: warning: GREP_OPTIONS is deprecated; please use an alias or script
grep (GNU grep) 3.3
Packaged by Homebrew
...
Related
I have been trying to run the usr/bin/time command in my terminal (Bash) with the verbose flag --verbose or -v but have repeatedly been getting this error:
/usr/bin/time: illegal option -- v
usage: time [-lp] command.
The command I have been running looks like basically like this:
/usr/bin/time -v python practice.py
Any ideas how to get this to work properly on a Mac? (I have OS X Yosemite)?
If you have homebrew, you can get GNU time by installing the gnu-time package:
brew install gnu-time
After that, it’s available as the gtime command:
$ gtime
Usage: gtime [-apvV] [-f format] [-o file] [--append] [--verbose]
[--portability] [--format=format] [--output=file] [--version]
[--help] command [arg...]
The case is similar for a lot of other homebrew-packaged GNU utilities for OSX; e.g., you can get the GNU df command with gdf, du with gdu, readlink with greadlink, etc.
The homebrew package that has most of those is coreutils, which installs about a hundred different GNU-flavored commands. Other useful packages: findutils, gnu-sed, gnu-tar.
If you don’t have homebrew installed yet, you can get it with just a single command:
Command to download and install homebrew
ruby -e "$(curl -fsSL\
https://raw.githubusercontent.com/Homebrew/install/master/install)"
I think looking at the man page the verbose flag is GNU only. Unfortunately, OSX implementation simply differs.
I'm a beginner in bash script and cannot solve the following problem: I have a file where each line is a xml file. I would like to divide each line into several lines.
For instance, I would like to put the following line:
<LumiBlockCollection><Run>201556</Run><LBRange Start="1020" End="1030"/></LumiBlockCollection>
into the format:
<LumiBlockCollection>
<Run>201556</Run>
<LBRange Start="1020" End="1030"/>
</LumiBlockCollection>
Does anyone know how to solve this problem?
In general, for a robust solution that works with varying input data, you should use an XML parser for this task:
A solution based on xmllint - xmllint is a standard utility on OS X and some Linux distros (e.g., Fedora):
echo '<LumiBlockCollection><Run>201556</Run><LBRange Start="1020" End="1030"/></LumiBlockCollection>' \
| XMLLINT_INDENT= xmllint --format - | tail -n +2
If your Linux distro does not come with xmllint, chances are that it can be installed with your platform's package manager; e.g., on Debian-based distros such as Ubuntu:
sudo apt-get install libxml2-utils
Another solution, based on third-party utility xmlstarlet:
echo '<LumiBlockCollection><Run>201556</Run><LBRange Start="1020" End="1030"/></LumiBlockCollection>' \
| xmlstarlet fo --omit-decl --noindent
Obtaining xmlstarlet:
OSX: Install via Homebrew with brew install xmlstarlet
Linux: chances are that it can be installed with your platform's package manager; e.g., on Debian-based distros such as Ubuntu: sudo apt-get install xmlstarlet
Here's a simple solution using sed. Note that if you have CDATA sections, this will place them on their own line:
$ xml='<LumiBlockCollection><Run>201556</Run><LBRange Start="1020" End="1030"/></LumiBlockCollection>'
$ echo $xml | sed 's/></>\n</g'
<LumiBlockCollection>
<Run>201556</Run>
<LBRange Start="1020" End="1030"/>
</LumiBlockCollection>
$
Im trying to install eclim on OSX 10.8.5 and the installer fails because it does not like the grep I have installed.
[ANT][exec]configure: error: no acceptable grep could be found
[ANT][exec] checking for grep that handles long lines and -e...
My grep has -e
SYNOPSIS
grep [OPTIONS] PATTERN [FILE...]
grep [OPTIONS] [-e PATTERN | -f FILE] [FILE...]
What is going on here?
I ended up fixing this by using macports to install gcc grep. Apparently OSX now uses bsd grep by default and there are differences between the two that gcc was choking on. The part of this that a little ridiculous is that I installed gcc through XCode.
Is there a way to isolate the list of new packages added to homebrew?
When I run brew upgrade it lists all the new packages,
and I want to open their homepage to see if I want to use them.
Something along the lines of
$ brew home $(brew list --new)
which iterates through all the new packages and opens their homepage...
So you can string a couple commands to do this:
List the outdated packages:
$ brew outdated
git (1.8.5.1, 1.9.0, 2.0.0 < 2.2.0)
brew home only wants the name, not the versions, so parse that out
$ brew outdated | awk '{print $1}'
git
Run brew home:
$ brew home `brew outdated | awk '{print $1}'`
OR
$ brew outdated | awk '{print $1}' | xargs brew home
Optional: My machine errors out LSOpenURLsWithRole() failed with error -1712 if I try to open more then 6 urls. Quick googling suggests that it's a timeout, which suggests that your machine and browser may time out after more or less urls.
$ for package in `brew outdated | awk '{print $1}'`; do brew home $package; done
I installed rvm 1.9.3 and now whenever I switch to a directory containing a .rvmrc, I get a perl error message:
~/example$ cd .. && cd example
perl version 5.12.3 can't run /usr/bin/shasum. Try the alternative(s):
/usr/bin/shasum5.10.0 (uses perl 5.10.0)
Run "man perl" for more information about multiple version support in
Mac OS X.
You may try this dirty approach. This approach will skip those check and directly use shasum in your binary directory
$ cd /usr/bin
$ ls shasum*
shasum shasum5.10.0
$ mv /usr/bin/shasum /usr/bin/your_backup_shasum
$ ln -s shasum5.10.0 shasum