cmdchallenge icon indicating copy to clipboard operation
cmdchallenge copied to clipboard

find_tabs_in_a_file: not accepting solution as valid

Open benko opened this issue 8 years ago • 8 comments

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

  1. enter "grep -c '\t' file-with-tabs.txt"
  2. see how it doesn't work
  3. bang head against table

benko avatar Feb 02 '17 10:02 benko

I don't want to reveal the answer but you're missing an option there.

gokaygurcan avatar Feb 02 '17 11:02 gokaygurcan

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

benko avatar Feb 02 '17 11:02 benko

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>`

tomleo avatar Feb 02 '17 14:02 tomleo

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 avatar Feb 02 '17 14:02 benko

@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 avatar Feb 02 '17 15:02 tomleo

@tomleo, so what we can conclude is that either the instructions are incomplete or the solution list is.

benko avatar Feb 02 '17 15:02 benko

@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.

tomleo avatar Feb 02 '17 15:02 tomleo

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.

benko avatar Feb 02 '17 15:02 benko