===== file.txt ======
AAA -1 2008-07-14
BBB -14 2008-07-15
CCC -20 2008-07-16
DDD -1 2008-07-16
===========
I tried:
grep -c -- "-1\t" file.txt
which is not working. I know I can do it with awk, like:
awk -F'\t' '$2==-1{t++}END{print t}' file.txt
But I would rather find a `grep` solution, any thought?? many thanks,
lihao
grep -c -- $'-1\t' file.txt
$'...' is ksh93/zsh/bash specific.
>
> which is not working. I know I can do it with awk, like:
>
> awk -F'\t' '$2==-1{t++}END{print t}' file.txt
>
> But I would rather find a `grep` solution, any thought?? many thanks,
[...]
Why, the awk solution looks a lot neater to me as closer to your
requirements.
Another one:
cut -f2 < file.txt | grep -cFxe -1
--
Stéphane
wow, this is impressive. do you mind to explain what exactly is the
different between $'...' and '...'. I've never seen this $'..' thing
before. :-) many thanks
>
> > which is not working. I know I can do it with awk, like:
>
> > awk -F'\t' '$2==-1{t++}END{print t}' file.txt
>
> > But I would rather find a `grep` solution, any thought?? many thanks,
>
> [...]
>
> Why, the awk solution looks a lot neater to me as closer to your
> requirements.
yes, just want to ask 'WHY' that grep line is not working...
> Another one:
>
> cut -f2 < file.txt | grep -cFxe -1
nice solution, :-)
thanks again,
lihao
> --
> Stéphane