Note that the syntax that the shell uses to glob for files (select multiple files) is NOT the same as normal (perl style or grep style) regular expressions. Also make sure that you run your grep command from within the directory - otherwise, grep will include the path to every file, and that will mess with your output. You will need to make sure that your grep command includes the golden file and excludes out.gold. That is, if you run diff between out.gold and your grep output, there should be no output. Out.gold is what your grep command should output. If a number is mal-formed, like the missing parens case for Numbers 4 or the missing dashes case for Numbers 5, you SHOULD NOT match those numbers.Įach directory has a "golden" file that has all of the phone numbers. Each successive file adds a new way that numbers can be formatted. Numbers 1 is the easiest and Numbers 5 is the hardest. Your task will be to make a regular expression that matches all of the well-formed phone numbers in every file in the directory. Each of them has phone numbers intermixed with text. Once you've untarred, open it and cd into the phone-numbers directory. There are 5 numbers directories. tar.gz), you will need to use tar -xvf rather than tar -xvzf.Ĥ. If the file is not gzipped (ie, the format ends in. To extract (x) and display verbose (v) information from a gzipped (z) file (f). Otherwise, a command like this will not work:Īnd you will have to escape characters like this:ģ. If you're unsure, type "man grep" and see if the -P flag exists. If you're running any version of OSX below 10.8, you should still have support for the -P flag with grep. With an upgrade to OSX 10.8, Apple removed support for this feature. To do this in zsh or bash, add the following line to your ~/.zshrc or ~/.bashrc file:Īlso, Macs do not have the -P flag for access to perl style regular expressions with grep. If you aren't using perl style regular expressions, a lot of the stuff in the videos won't work. This will use perl style regular expressions. Make sure that you have an alias from grep to grep -P (capitalization matters). If you're on a myth machine, you're running csh by default.Ģ. zsh is much more intuitive in how it deals with special characters and quotes and such. Watch the grep videos and learn to love regular-expressions.ġ. optional: (abc)? - the preceding group is optional.optional: (abc | def) match either abc or def.\w : any word character, anything alphanumeric.If you have: (group1) (group2) then \1 and \2 will refer to group1 and group2 respectively.if you only care that “hello” is at the end of the line.^ is the starting invisible character for a line.match all lines that don’t contain numbers.* character: repeat 0 or more times not 1 or more.if your expression contains a space, either surround the string in quotation marks or escape the space using a backslash to tell the computer that the space is not a real space, it’s part of the expression (i.e., the space isn’t separating arguments to grep).grep makes sure that “sofiaavila” is in the output files.locate doesn’t allow you to specify a directory so you can use grep:.to use you must first update the database with: sudo updatedb.locate is faster than find because it uses databases:. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |