15

I ran this command:

grep -i 'bro*' shows.csv

and got this as output

1845307,2 Broke Girls,2011,138,6.7,89093
1702042,An Idiot Abroad,2010,21,8.3,29759
903747,Breaking Bad,2008,62,9.5,1402577
2249364,Broadchurch,2013,24,8.4,89378
1733785,Bron/Broen,2011,38,8.6,56357
2467372,Brooklyn Nine-Nine,2013,145,8.4,209571
7569592,Chilling Adventures of Sabrina,2018,36,7.6,69041
7221388,Cobra Kai,2018,31,8.7,72993
1355642,Fullmetal Alchemist: Brotherhood,2009,69,9.1,111111
118360,Johnny Bravo,1997,67,7.2,32185
455275,Prison Break,2005,91,8.3,465246
115341,Sabrina the Teenage Witch,1996,163,6.6,33458
1312171,The Umbrella Academy,2019,20,8,140800
3339966,Unbreakable Kimmy Schmidt,2015,51,7.6,61891

Where is bro in breaking bad? In fact, o doesn't even appear in "Breaking bad". I tried it once more, and got the same result. It is not accounting for the last character. Is there something wrong in the way I am writing it?

You can download the file shows.csv from https://cdn.cs50.net/2021/x/seminars/linux/shows.csv

1
78

In your code o* means "zero or more occurrences of o". It seems you confused regular expressions with glob syntax (where o* means "one o and zero or more whatever characters").

In Breaking Bad there is exactly zero o characters after Br, so it matches bro* (case-insensitively).

grep -i bro shows.csv will do what (I think) you want.

0

Here the o* implies "zero or more". If you want the desired output with the asterisk, you can just add a random alphabet after o like this:

$ grep -i "broa*" shows.csv

1845307,2 Broke Girls,2011,138,6.7,89093 1702042,An Idiot Abroad,2010,21,8.3,29759 2249364,Broadchurch,2013,24,8.4,89378 1733785,Bron/Broen,2011,38,8.6,56357 2467372,Brooklyn Nine-Nine,2013,145,8.4,209571 1355642,Fullmetal Alchemist: Brotherhood,2009,69,9.1,111111

Else, grep -i "bro" shows.csv will work.

HTH.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.