![]() ![]() You should use grep -E '^.+$' filename.txt ![]() Other characters that are special to the shell ( >, #, and the like) might lead to even more unexpected behavior. If your pattern contains $ or globbing characters ( *, ? and character lists!), the shell may try to perform variable expansion (thereby replacing parts of your RegEx) or expand globbing patterns into possibly multiple filenames, so that in the end you would have more arguments on the command-line that you originally intended. That means any characters are open to interpretation by the shell before they are passed to the grep command. In your example, you use the regular expression unquoted. ![]() (1)for what it might actually do, see below and only contain letters (but at least one) up to the end of the line.So, your RegEx is intended to (1) match any lines that The $ is an anchor that ties this position of the regex to the end of the line.The + means "one or more of the previous".Again, what that means depends on the collation order! The again is a character list and will match characters (1) that fall between a and z and in addition those that fall between A and Z.What exactly that comprises depends on the "collation order", determined among others by the environment variable LC_COLLATE. The is a character list and will match any single (1) character that falls into the sort range between 0 and 9.The ^ is an anchor that ties this position of the regex to the start of the line.First of all, note that this RegExp uses the "Extended regular expression" syntax (ERE) - the + is a metacharacter that doesn't work in the "Basic regular expression" syntax that grep uses by default (meaning it would match itself and require a literal + at that position), so if you want to use that RegEx with grep, you will need to pass the -E option. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |