Home > front end >  getting diffrent results from a hackerrank bash practice than my acutal bash
getting diffrent results from a hackerrank bash practice than my acutal bash

Time:10-03

I have been doing some hackerrank practices, mainly about the grep shell command. The challenge asks me to detect a pattern on bank cards number, which is to detect pair of numbers next to each other, or with a space in between. Here is an example of the pattern :

5678 910my attempt on Gnu/Linux bash

However, i get false output, or i strictly saying (different output than my OS bash)

Hackerrank's bash

Here's the challenge link : https://www.hackerrank.com/challenges/text-processing-in-linux-the-grep-command-5/problem

my question is:

  • does the bash shell on Hackerrank works differently than my OS bash shell ? if YES, then what are the differences and is there any resources that i can rely on. In case the answer is NO, then why the outputs differ ?

CodePudding user response:

For some reason, Hackerrank requires the use of POSIX BRE here.

You can use

grep '\([0-9]\)[[:space:]]*\1'
grep '\([0-9]\) *\1'
grep '\([0-9]\)\s*\1'

The \(...\) is used to define a capturing group in POSIX BRE regex.

  • Related