Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

find_tabs_in_a_file: not accepting solution as valid #90

Open
benko opened this issue Feb 2, 2017 · 8 comments
Open

find_tabs_in_a_file: not accepting solution as valid #90

benko opened this issue Feb 2, 2017 · 8 comments

Comments

@benko
Copy link

benko commented Feb 2, 2017

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
@gokaygurcan
Copy link

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

@benko
Copy link
Author

benko commented Feb 2, 2017

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

@tomleo
Copy link

tomleo commented Feb 2, 2017

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>

@benko
Copy link
Author

benko commented Feb 2, 2017

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?

@tomleo
Copy link

tomleo commented Feb 2, 2017

@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

@benko
Copy link
Author

benko commented Feb 2, 2017

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

@tomleo
Copy link

tomleo commented Feb 2, 2017

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

@benko
Copy link
Author

benko commented Feb 2, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants