grep: Unknown option -C - windows

I want grep to print 2 lines before and after the matching line.
I am using GnuWin32 grep(2.5.4). But it is showing error as follows:
grep: Unknown option -C
Usage: grep [-clqinsvxEF] [-bI] [-e pattern] [-f patternfile] [pattern] [file ...]
As per my understanding from the error, the -C option is not supported by GnuWin32.
So my doubt is The GnuWin32 grep will not support -C option or any updated version is there for GnuWin32 grep which would support -C option....

Related

mv command not working on mac

Here is the part of the makefile that is giving me issues:
-#mv -f -t ./ $(LIBPATH)/userfiles/*
When I run the makefile on Ubuntu it works fine however when running on my Mac I get the following error:
mv: illegal option -- t usage: mv [-f | -i | -n] [-v] source target
mv [-f | -i | -n] [-v] source ... directory
The -t flag is not defined in the man pages of my mac so I'm wondering how I can get around this.
Just put the destination at the end like how mv is normally used:
-#mv -f $(LIBPATH)/userfiles/* .
You are allowed to have multiple sources (such as the expanded wildcard here). The last argument is the destination. The -t flag is just a way to change this ordering if you have to for some reason, and (as you discovered) it is not always available.
Install coreutils by typing the following command in the terminal:
brew install coreutils
Commands also provided by macOS and the commands dir, dircolors, vdir 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 with:
PATH="$(brew --prefix)/opt/coreutils/libexec/gnubin:$PATH"
Reference:
coreutils - Homebrew Formulae

Describe: "Require at least one option" in usage

What is the proper way to convey the notion of "one or more of the following option flags must be present -a -b -c" in a bash usage message?
(Details on similar problems/solutions, to show my current attempts follow.)
I know how to specify a required argument:
usage: ./my_script.sh arg_matey.html
I also know how to specify an optional argument such as -x:
usage: ./my_script.sh [-x] marks_the_spot.py
I even know how to make mutually exclusive optional arguments:
usage: ./my_script.sh [-p | -i | -r | -a | -t | -e] walk_the_plank.txt
But no combination of those seems to satisfy the notion of 1+ option from a list must be used.
Consider using a multi line usage statement.
usage: ./my_script.sh flag walk_the_plank.txt
Flags: [-p | -i | -r | -a | -t | -e]

Installing eclim on osx 10.8.5 fails - no acceptable grep found

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.

Sort in Makefile

I have this in my makefile
test:
cat t.txt | sort -t $$'\t' -k 2,2
But "make test" gives me this error
cat t.txt | sort -t $'\t' -k 2,2
sort: multi-character tab `$\t'
make: * [test] Error 2
Works fine on Redhat linux but fails on Ubuntu linux
The $'\t' syntax you're trying to use is a bash-ism, but by default gmake uses /bin/sh as the shell. You can either override the SHELL variable in your makefile, as in:
SHELL=/bin/bash
or explicitly invoke bash for this specific command:
test:
bash -c "cat t.txt | sort -t $$'\t' -k 2,2"
Q: What OS is this failing on?
SUGGESTION:
How do I sort a tab separated file on the nth column using cygwin sort?
http://linux.derkeiler.com/Mailing-Lists/Fedora/2008-03/msg02180.html
You can substitute an actual tab, e.g. sort -t "<Ctl-V><Tab>"

Strange behavior of uniq on darwin shells

I've used 'uniq -d -c file' in many shell scripts on linux machines, and it works.
On my MAC (OS X 10.6.7 with developer tools installed) it doesn't seems to work:
$ uniq -d -c testfile.txt
usage: uniq [-c | -d | -u] [-i] [-f fields] [-s chars] [input [output]]
It would be nice if anyone could checks this.
Well, it's right there in the Usage message. [ -c | -d | -u] means you can use one of those possibilities, not two.
Since OSX is based on BSD, you can check that here or, thanks to Ignacio, the more Apple-specific one here.
If you want to achieve a similar output, you could use:
do_your_thing | uniq -c | grep -v '^ *1 '
which will strip out all those coalesced lines that have a count of one.
You can try this awk solution
awk '{a[$0]++}END{for(i in a)if(a[i]>1){ print i ,a[i] } }' file

Resources