Apache web server for windows - 254 CHAPTER 15 WORKING WITH TEXT FILES
254 CHAPTER 15 WORKING WITH TEXT FILES grep is very powerful. It can be complicated to master, but it offers a lot of scope for performing extremely precise searches that ensure you find only what you re seeking. It s well worth reading through its man pages. You can also refer to books on the subject, of which there are many. A good example is Regular Expression Recipes: A Problem-Solution Approach, by Nathan A. Good (1-59059-441-X; Apress, 2004). Comparing Text Files If you want to compare the differences between two text files, one way to do this is to use the diff command. This is designed primarily to uncover small changes in otherwise identical documents, such as revisions made by another person. Of course, it can also be used to prove that two files are identical. If you run the files through diff, and it shows no output, it has been unable to spot any differences. diff is ordinarily used like this: diff mytextfile1 mytextfile2 If diff spots any differences between the files, the results are a little more complicated than you might be used to. Any lines that are different within the files will appear on screen. Those lines that are identical won t be displayed. Lines preceded with a left angle bracket (<) are from the first file, while those with a right angle bracket (>) are from the second file. For a different display, you could type something like this: diff y mytextfile1 mytextfile2 This places the two lists side-by-side and highlights lines that are different with a pipe symbol (|). However, it requires a lot more screen space than using diff without the -y option. Note When you use the -y command option with diff, it will struggle to fit the output in a standard GNOME Terminal window. If it is maximized on a 17-inch screen (1024 768 resolution), it should be just large enough to fit the information in, depending on the complexity of the files being compared. By specifying the -a command option, you can make diff process binary files, too. This is a handy way of comparing virtually any kind of files, including program files, to see if they re identical. If there s no output from diff, then the two files are identical. If your screen fills with gibberish, then the files are clearly different. Incidentally, if you want to compare three documents, you can use a very similar command: diff3. Check the command s man page to learn more about how it works.