7.miscellaneous Text Utilities

tr the tr utility is used to translate specified characters into other characters or to delete them. tr [options] set1 [set2] set1: to be replaced or removed set2: to be substituted for the characters listed in the first argument. tr ‘{}’ ‘()’ < inputfile > outputfile translate braces into parenthesis echo " … " | tr [:space:] ‘\t’ translate white-space to tabs echo “This is for testing” | tr -s [:space:]...

December 25, 2023 · nolleh

6.grep

grep grep [0-9] print the lines that contain the numbers 0 through 9 grep -C 3 [pattern] print context of lines (specified number of lines above and below the pattern) for matching the pattern. Here, the number of lines is specified as 3 strings strings is used to extract all character strings found in the file or files given as arguments. it is useful in locating human-readable content embedded in binary files; for text files one can just use grep...

December 25, 2023 · nolleh

5.file Manipulation Utilities

sort sort -k 3 sort the lines by the 3rd field on each line instead of the beginning sort -u equivalent to run uniq after sort uniq uniq removes duplicate consecutive lines in a text file and is useful for simplifying the text display uniq requires that the duplicate entries must be consecutive, one often runs sort first and then pipes the output into uniq; to count the number of duplicate entries, use the following command:...

December 25, 2023 · nolleh

4.sed and Awk

introduction to sed and awk many Linux users and administrators will write scripts using comprehensive scripting languages such as Python and perl, rather than use sed and awk. However, the utilitites that are described here are much lighter;i.e. they use fewer system resources, and execute faster. sed abbreviation for stream editor. data from an input source/file (or stream) is taken and moved to a working space. the entire list of operations/modifications is applied over the data in the working space and...

December 25, 2023 · nolleh

3.working With Large and Compressed Files

working with large files directly opening the file in an editor will probably be inefficient (due to high memory utilization) because most text editors usually try to read the whole file into memory first. instead, one can use less to view the contents of such a large file, scrolling up and down page by page, without the system having to place the entire file in memory before starting. less somefile cat somefile | less head reads the first few lines...

December 25, 2023 · nolleh