90 likes | 229 Views
String Processing. Word Counting. Linux stores text in files using an encoding scheme. The most popular is ASCII encoding. Using ‘ wc ’ command, we can count the number of lines, characters and words in a file.
E N D
Word Counting Linux stores text in files using an encoding scheme. The most popular is ASCII encoding. Using ‘wc’ command, we can count the number of lines, characters and words in a file. The ‘head’ and ‘tail’ commands allows us to examine the first or last few lines of a text file.
Text searching • There are a few tools for searching text. They are:- • fgrep Does a fast search for simple patterns. • grep Pattern searches using ordinary regular expressions. • egrep Pattern searches using more powerful extended regular expressions. • Normally, we use ‘grep’ to search for text.
Regular Expressions Regular expressions are a standard Unix syntax for specifying text patterns. Regular expressions are understood by many commands, including grep Within regular expressions, . and [] are used to match characters. Within regular expressions, +, *, and ?specify a number of consecutive occurrences. Within regular expressions, ^ and $ specify the beginning and end of a line. Within regular expressions, (, ), and | specify alternative groups. The regex(7) man page provides complete details.
More tools To sort text in a file, use ‘sort’. To cut text in a file, use ‘cut’. To find out differences between two files, use ‘diff’. To spell-check a file use ‘aspell’. The fmt command can reformat text to differing widths. The split command can be used to split a single file into multiple files based on either a number of lines or a number of bytes.