Note that we could have run this particular command without the -F option. The -f argument tells grep to get its patterns from the specified file rather than from the command line. When we then want to select from another file all of the lines that contain these color names. Say we have a list of colors in one file: You can also put a series of literal strings in a file and look for them all using a command as in the example below. Here's an option that provides some interesting benefits. Because of this literalism, fgreg (i.e., grep -F) commands tend to run a little faster than oither grep commands. The $ in the command below, for example, is not taken as indicating that some kind of interpretation is needed. This means that it doesn't interpret any expressions that you specify, but takes them literally. With -F, grep interprets that patterns you provide as fixed strings. This means that you can provide a string of expressions that you want to match as shown in the example below. With the -E switch, grep uses extended regular expressions. So, you can use the options or set up the aliases to make using them a bit easier. They're just built into a single executable on most systems today. If you've used egrep and fgrep in the past, you'll find that grep -E and grep -F work as you'd expect. To easily switch from one mode of searching to another, the different grep commands could be set up as aliases such as these: alias egrep='grep -E' Historically provided as separate binaries, the different “flavors” of grep are now provided through a number of key command options that change how grep interprets the pattern that you provide for your search. It can take on some vastly different personalities that allow you to more cleverly find the data that you are looking for and has more flexibility than many of its users have discovered. The grep command – likely one of the first ten commands that every Unix user comes to know and love – is not just a nice tool for finding a word or phrase in a file or command output.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |