[ Pobierz całość w formacie PDF ]
.Searches for a regular expression.While a regular expression can be quite complicated, you canjust type in a text string to search for.For example, toad return would search for the nextoccurence of toad" in your current le.A slash followed by a return will search for the nextoccurence of what you last searched for.n This will also search for the next occurence of your regular expression.: n If you speci ed more than one le on the command line, this will move to the next le.: p This will move the the previous le.q Exits from more.66 CHAPTER 7.POWERFUL LITTLE PROGRAMShead -lines le1 le2.leNhead will display the rst ten lines in the listed les, or the rst ten lines of stdin if no les arespeci ed on the command line.Any numeric option will be taken as the number of lines to print,so head -15 frog will print the rst fteen lines of the le frog.tail -lines le1 le2.leNLike head, tail will display only a fraction of the le.Naturally, tail will display the end of thele, or the last ten lines that come through stdin.tail also accepts a option specifying the numberof lines.file le1 le2.leNThe file command attempts to identify what format a particular le is written in.Since not allles have extentions or other easy to identify marks, the file command performs some rudimentarychecks to try and gure out exactly what it contains.Be careful, though, because it is quite possible for file to make a wrong identi cation.7.5 Information CommandsThis section discusses the commands that will alter a le, perform a certain operation on the le,or display statistics on the le.grep -nvwx -number expression le1 le2.leNOne of the most useful commands in Unix is grep, the generalized regular expression parser.This is a fancy name for a utility which can only search a text le.The easiest way to use grep islike this:home larry cat animalsAnimals are very interesting creatures.One of my favorite animals isthe tiger, a fearsome beast with large teeth.I also like the lion---it' s really neat!home larry grep iger animalsthe tiger, a fearsome beast with large teeth.home larryOne disadvantage of this is, although it shows you all the lines containing your word, it doesn't7.5.INFORMATION COMMANDS 67tell you where to look in the le|no line number.Depending on what you're doing, this might bene.For instance, if you're looking for errors from a programs output, you might try a.out | greperror, where a.out is your program's name.If you're interested in where the match es are, use the n switch to grep to tell it to print linenumbers.Use the v switch if you want to see all the lines that don' t match the speci ed expression.Another feature of grep is that it matches only parts of a word, like my example above whereiger matched tiger.To tell grep to only match whole words, use the w, and the x switch will tellgrep to only match whole lines.If you don't specify any les, grep will examine stdin.wc -clw le1 le2.leNwc stands for word count.It simply counts the number of words, lines, and characters in thele s.If there aren't any les speci ed on the command line, it operates on stdin.The three parameters, clw, stand for character, line, and word respectively, and tell wc whichof the three to count.Thus, wc -cw will count the number of characters and words, but not thenumber of lines.wc defaults to counting everything|words, lines, and characters.One nice use of wc is to nd how many les are in the present directory: ls | wc -w.If youwanted to see how many les that ended with.c there are, try ls *.c | wc -w.spell le1 le2.leNspell is a very simple Unix spelling program, usually for American English.3 spell is a lter,like most of the other programs we've talked about, which sucks in an ASCII text le and outputsall the words it considers misspellings.spell operates on the les listed in the command line, or, ifthere weren't any there, stdin.A more sophisticated spelling program, ispell is probably also available on your machine
[ Pobierz całość w formacie PDF ]