cmdchallenge
cmdchallenge copied to clipboard
find_tabs_in_a_file: not accepting solution as valid
Summary
https://cmdchallenge.com/#/find_tabs_in_a_file The problem is (also) solvable using "grep -c '\t' file-with-tabs.txt", however, it is not accepted.
Steps to reproduce
- enter "grep -c '\t' file-with-tabs.txt"
- see how it doesn't work
- bang head against table
I don't want to reveal the answer but you're missing an option there.
No. See:
$ grep -V
grep (GNU grep) 2.20
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Mike Haertel and others, see <http://git.sv.gnu.org/cgit/grep.git/tree/AUTHORS>.
$ cat afile # those are of course tabs down there
kadfngsjdfngstdkfngvsfkjghd
sarjfghartj sdkfjgdlfjg
dkfgjnsdlagjksdrkglsrkfgjlr
kfdlsjgslk kfdgnjldfgs
sdkfjgdfksjgkdfjgldfjgldkfj
$ grep -c '\t' afile
2
Different versions of grep support different types of escapes.
tom@computer:~$ echo '\t'
\t
tom@computer:~$ echo $'\t'
```
For more info about bash escaping see http://tldp.org/LDP/abs/html/escapingsection.html
Grep supports different regex engines with slightly different behaviors, which is an alternative way to get something like `\t` to be interpreted as a `<tab>`
sooo... how does this change the fact that a working solution (verified by gnu grep 2.20 and bsd grep 2.5) does not work in the challenge?
@benko Different versions of bash and grep don't tell the whole story. Below is the output from my computer. I'm not familiar with BSD, but if you look at the dockerfile for this project, they're using Ubuntu 16.04 which may account for the differences in behavior.
Warning: Spoiler alert
tom@computer:~$ grep -V
grep (GNU grep) 2.25
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Mike Haertel and others, see <http://git.sv.gnu.org/cgit/grep.git/tree/AUTHORS>.
tom@computer:~$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.1 LTS"
tom@computer:~$ grep '\t' file-with-tabs.txt
tom@computer:~$ grep $'\t' file-with-tabs.txt
a
c
e
tom@computer:~$ grep '\x09' file-with-tabs.txt
tom@computer:~$ grep $'\x09' file-with-tabs.txt
a
c
e
@tomleo, so what we can conclude is that either the instructions are incomplete or the solution list is.
@benko It's possible the solution list is incomplete, but grep '\t'
doesn't work in an Ubuntu bash prompt which is what the command line challenge is using.
then be clear about it. unix is about being portable as much as it is about knowing the specifics of the environment you're currently working in. precisely for the reason of being portable.