### cut command example with /etc/passwd input Source: https://ftp.gnu.org/old-gnu/Manuals/textutils-1.22/html_mono/textutils.html Shows a sample line from /etc/passwd, which has seven fields separated by colons. This is the input for the cut example. ```text arnold:xyzzy:2076:10:Arnold D. Robbins:/home/arnold:/bin/ksh ``` -------------------------------- ### wc --bytes --words example Source: https://ftp.gnu.org/old-gnu/Manuals/textutils-1.22/html_mono/textutils.html Example showing that wc options do not undo each other; this prints both byte and word counts. ```shell wc --bytes --words ``` -------------------------------- ### Unix Shell Data Pipeline Example Source: https://ftp.gnu.org/old-gnu/Manuals/textutils-1.22/html_mono/textutils.html Example of a Unix shell pipeline that creates data, applies successive filters, and redirects the final output to a file. Demonstrates the use of standard input/output and filters. ```shell program_to_create_data | filter1 | .... | filterN > final.pretty.data ``` -------------------------------- ### cut command example with -d and -f options Source: https://ftp.gnu.org/old-gnu/Manuals/textutils-1.22/html_mono/textutils.html Shows how to use cut with -d: and -f1,5 to print the first and fifth fields from /etc/passwd. The output includes the login name and full name. ```shell $ cut -d: -f1,5 /etc/passwd root:Operator ... arnold:Arnold D. Robbins miriam:Miriam A. Robbins ... ``` -------------------------------- ### who command example with output Source: https://ftp.gnu.org/old-gnu/Manuals/textutils-1.22/html_mono/textutils.html Shows the output of running the who command, listing logged-in users. The $ is the shell prompt. On traditional Unix systems, user names are never more than eight characters long. ```shell $ who arnold console Jan 22 19:57 miriam ttyp0 Jan 23 14:19(:0.0) bill ttyp1 Jan 21 09:32(:0.0) arnold ttyp2 Jan 23 20:48(:0.0) ``` -------------------------------- ### comm f1 f2 example with cat f1 and cat f2 Source: https://ftp.gnu.org/old-gnu/Manuals/textutils-1.22/html_mono/textutils.html Shows the output of comm on two sorted files f1 and f2. The output has three columns: lines unique to f1, lines unique to f2, and common lines. The -1, -2, -3 options omit respective columns. ```shell $ cat f1 11111 22222 33333 44444 $ cat f2 00000 22222 33333 55555 $ comm f1 f2 00000 11111 22222 33333 44444 55555 ``` -------------------------------- ### Sample output of uniq -c word count Source: https://ftp.gnu.org/old-gnu/Manuals/textutils-1.22/html_mono/textutils.html Example output showing word counts sorted alphabetically, not by frequency. ```shell 60 a 2 able 6 about 1 above 2 accomplish 1 acquire 1 actually 2 additional ``` -------------------------------- ### Sort password file using global -b modifier Source: https://ftp.gnu.org/old-gnu/Manuals/textutils-1.22/html_mono/textutils.html Alternative to the previous example using the global -b modifier instead of -n, with an explicit 'n' on the second key specifier. The -k 5,5 ignores leading and trailing whitespace globally. ```shell sort -t : -b -k 5,5 -k 3,3n /etc/passwd ``` -------------------------------- ### sort -k3: Sort alphabetically omitting first two fields Source: https://ftp.gnu.org/old-gnu/Manuals/textutils-1.22/html_mono/textutils.html Sorts lines alphabetically using a single key that starts at field three and extends to the end of each line. Fields are separated by whitespace by default. ```shell sort -k3 ``` -------------------------------- ### Final word frequency pipeline with sort -nr Source: https://ftp.gnu.org/old-gnu/Manuals/textutils-1.22/html_mono/textutils.html Complete pipeline: lowercase, remove punctuation, squeeze blanks, sort, count with uniq -c, then sort -nr for numeric reverse order to get most frequent words first. ```shell $ tr '[A-Z]' '[a-z]' < whats.gnu | tr -cd '[A-Za-z0-9_ \012]' | > tr -s '[ ]' '\012' | sort | uniq -c | sort -nr 156 the 60 a 58 to 51 of 51 and ... ``` -------------------------------- ### Sort password file using global numeric modifier -n Source: https://ftp.gnu.org/old-gnu/Manuals/textutils-1.22/html_mono/textutils.html Alternative to the previous example using the global numeric modifier -n instead of the 'n' modifier on the second key. The -k 5b,5 still ignores leading whitespace on the fifth field. ```shell sort -t : -n -k 5b,5 -k 3,3 /etc/passwd ``` -------------------------------- ### wc synopsis Source: https://ftp.gnu.org/old-gnu/Manuals/textutils-1.22/html_mono/textutils.html Shows the general command-line syntax for wc. ```shell wc [option]... [file]... ``` -------------------------------- ### sum synopsis Source: https://ftp.gnu.org/old-gnu/Manuals/textutils-1.22/html_mono/textutils.html Shows the general command-line syntax for sum. ```shell sum [option]... [file]... ``` -------------------------------- ### split synopsis: split [option] [input [prefix]] Source: https://ftp.gnu.org/old-gnu/Manuals/textutils-1.22/html_mono/textutils.html Shows the command-line syntax for the split utility. The input defaults to standard input if omitted or given as '-', and the output file prefix defaults to 'x'. ```bash split [option] [input [prefix]] ``` -------------------------------- ### expand synopsis Source: https://ftp.gnu.org/old-gnu/Manuals/textutils-1.22/html_mono/textutils.html Usage synopsis for the expand command: expand [option]... [file]... ```bash expand [option]... [file]... ``` -------------------------------- ### fmt command synopsis Source: https://ftp.gnu.org/old-gnu/Manuals/textutils-1.22/html_mono/textutils.html Shows the general usage of the 'fmt' command. It reads from specified files or standard input and writes to standard output. ```bash fmt [option]... [file]... ``` -------------------------------- ### join synopsis Source: https://ftp.gnu.org/old-gnu/Manuals/textutils-1.22/html_mono/textutils.html Shows the command-line syntax for join. Requires two file arguments, one of which may be '-' for standard input. ```bash join [option]... file1 file2 ``` -------------------------------- ### uniq command synopsis Source: https://ftp.gnu.org/old-gnu/Manuals/textutils-1.22/html_mono/textutils.html Shows the general usage syntax for the `uniq` command. The input must be sorted; if not, use `sort -u`. If no output file is specified, output goes to standard output. ```text uniq [option]... [input [output]] ``` -------------------------------- ### Create listusers shell script with pipeline Source: https://ftp.gnu.org/old-gnu/Manuals/textutils-1.22/html_mono/textutils.html Creates a shell script /usr/local/bin/listusers containing the pipeline, then makes it executable with chmod. The ^D represents end-of-input. ```shell # cat > /usr/local/bin/listusers who | cut -c1-8 | sort | uniq ^D # chmod +x /usr/local/bin/listusers ``` -------------------------------- ### sort synopsis Source: https://ftp.gnu.org/old-gnu/Manuals/textutils-1.22/html_mono/textutils.html The general command-line syntax for the sort utility. ```text sort [option]... [file]... ``` -------------------------------- ### pr synopsis: pr [option]... [file]... Source: https://ftp.gnu.org/old-gnu/Manuals/textutils-1.22/html_mono/textutils.html Shows the command-line synopsis for the 'pr' utility. Files are written to standard output, paginated and optionally in multicolumn format; '-' means standard input. ```shell pr [option]... [file]... ``` -------------------------------- ### comm synopsis: comm [option]... file1 file2 Source: https://ftp.gnu.org/old-gnu/Manuals/textutils-1.22/html_mono/textutils.html Shows the command-line syntax for comm. The input files must be sorted before use. With no options, output has three columns: unique to file1, unique to file2, and common lines, separated by TAB. ```text comm [option]... file1 file2 ``` -------------------------------- ### Generate list of logged-in users with who and cut Source: https://ftp.gnu.org/old-gnu/Manuals/textutils-1.22/html_mono/textutils.html First step of the pipeline: generate a list of logged-on users by taking the first 8 characters of each line from the who command output. ```shell $ who | cut -c1-8 arnold miriam bill arnold ``` -------------------------------- ### head synopses Source: https://ftp.gnu.org/old-gnu/Manuals/textutils-1.22/html_mono/textutils.html Shows the two command-line synopses for head. The first is the standard form, and the second is the old-style form with a number before options. ```bash head [option]... [file]... ``` ```bash head -number [option]... [file]... ``` -------------------------------- ### cut synopsis: cut [option]... [file]... Source: https://ftp.gnu.org/old-gnu/Manuals/textutils-1.22/html_mono/textutils.html Shows the command-line syntax for cut. It reads from standard input if no files are given or if a file name is '-'. Byte, character, and field lists are comma-separated numbers or ranges, numbered from 1. ```text cut [option]... [file]... ``` -------------------------------- ### md5sum synopsis Source: https://ftp.gnu.org/old-gnu/Manuals/textutils-1.22/html_mono/textutils.html Shows the two command-line forms for md5sum: one for generating checksums and one for verifying them with --check. ```bash md5sum [option]... [file]... md5sum [option]... --check [file] ``` -------------------------------- ### Sort the user list with sort Source: https://ftp.gnu.org/old-gnu/Manuals/textutils-1.22/html_mono/textutils.html Second step: sort the list of users generated by who and cut. The output shows the sorted list with duplicates still present. ```shell $ who | cut -c1-8 | sort arnold arnold bill miriam ``` -------------------------------- ### unexpand synopsis Source: https://ftp.gnu.org/old-gnu/Manuals/textutils-1.22/html_mono/textutils.html Usage synopsis for the unexpand command: unexpand [option]... [file]... ```bash unexpand [option]... [file]... ``` -------------------------------- ### cat synopsis: cat [option] [file]... Source: https://ftp.gnu.org/old-gnu/Manuals/textutils-1.22/html_mono/textutils.html Shows the command-line syntax for the cat program. It copies each file (or standard input if none are given) to standard output. ```shell cat [option] [file]... ``` -------------------------------- ### csplit synopsis Source: https://ftp.gnu.org/old-gnu/Manuals/textutils-1.22/html_mono/textutils.html The command-line synopsis for csplit. It shows the general usage: csplit [option]... input pattern... ```text csplit [option]... input pattern... ``` -------------------------------- ### od --traditional syntax Source: https://ftp.gnu.org/old-gnu/Manuals/textutils-1.22/html_mono/textutils.html Shows the syntax for the pre-POSIX non-option arguments accepted when using --traditional. ```shell od --traditional [file] [[+]offset[.][b] [[+]label[.][b]]] ``` -------------------------------- ### paste synopsis Source: https://ftp.gnu.org/old-gnu/Manuals/textutils-1.22/html_mono/textutils.html Shows the command-line syntax for paste. Use it to merge lines from multiple files. ```bash paste [option]... [file]... ``` -------------------------------- ### cksum synopsis Source: https://ftp.gnu.org/old-gnu/Manuals/textutils-1.22/html_mono/textutils.html Shows the command-line syntax for cksum. It computes a CRC checksum for each file or standard input. ```bash cksum [option]... [file]... ``` -------------------------------- ### head file header format Source: https://ftp.gnu.org/old-gnu/Manuals/textutils-1.22/html_mono/textutils.html Shows the one-line header that head prints before the output for each file when more than one file is specified. ```bash ==> file name <== ``` -------------------------------- ### nl synopsis Source: https://ftp.gnu.org/old-gnu/Manuals/textutils-1.22/html_mono/textutils.html Shows the command-line synopsis for nl. It writes each file, or standard input if none are given, to standard output, with line numbers added to some or all of the lines. ```bash nl [option]... [file]... ``` -------------------------------- ### tail synopsis Source: https://ftp.gnu.org/old-gnu/Manuals/textutils-1.22/html_mono/textutils.html Shows the three synopsis forms for the `tail` command: standard, with a number, and with a plus number. ```shell tail [option]... [file]... tail -number [option]... [file]... tail +number [option]... [file]... ``` -------------------------------- ### tac synopsis Source: https://ftp.gnu.org/old-gnu/Manuals/textutils-1.22/html_mono/textutils.html Shows the command-line synopsis for tac. It copies each file, or standard input if none are given, to standard output, reversing the records in each separately. ```bash tac [option]... [file]... ``` -------------------------------- ### Generate tags file in case-insensitive sorted order Source: https://ftp.gnu.org/old-gnu/Manuals/textutils-1.22/html_mono/textutils.html Uses find with -print0, sort with -z and -f, and xargs -0 to generate a tags file. The -print0, -z, and -0 options prevent pathnames containing Line Feed characters from being broken up by the sort operation. ```shell find src -type f -print0 | sort -t / -z -f | xargs -0 etags --append ``` -------------------------------- ### od synopsis Source: https://ftp.gnu.org/old-gnu/Manuals/textutils-1.22/html_mono/textutils.html Shows the general usage of 'od' with options and files, and the traditional form with offset and label. ```shell od [option]... [file]... od -C [file] [[+]offset [[+]label]] ``` -------------------------------- ### tr lowercase, punctuation removal, squeeze, sort, uniq -c pipeline step 4 Source: https://ftp.gnu.org/old-gnu/Manuals/textutils-1.22/html_mono/textutils.html Fourth step: count each word using sort | uniq -c. The output is sorted by word, not by count. ```shell $ tr '[A-Z]' '[a-z]' < whats.gnu | tr -cd '[A-Za-z0-9_ \012]' | > tr -s '[ ]' '\012' | sort | uniq -c | ... ``` -------------------------------- ### tr lowercase conversion pipeline step 1 Source: https://ftp.gnu.org/old-gnu/Manuals/textutils-1.22/html_mono/textutils.html First step of word frequency counter: convert all letters to lowercase using tr '[A-Z]' '[a-z]' on input file whats.gnu. The ellipsis indicates the pipeline continues. ```shell $ tr '[A-Z]' '[a-z]' < whats.gnu | ... ``` -------------------------------- ### fold synopsis Source: https://ftp.gnu.org/old-gnu/Manuals/textutils-1.22/html_mono/textutils.html Shows the command-line synopsis for fold. It writes each file or standard input to standard output, breaking long lines. ```bash fold [option]... [file]... ``` -------------------------------- ### Map uppercase to lowercase with tr Source: https://ftp.gnu.org/old-gnu/Manuals/textutils-1.22/html_mono/textutils.html Uses tr to transliterate uppercase letters to lowercase in a sample string, demonstrating the basic usage of tr. ```shell $ echo ThIs ExAmPlE HaS MIXED case! | tr '[A-Z]' '[a-z]' this example has mixed case! ``` -------------------------------- ### Remove duplicate lines with uniq Source: https://ftp.gnu.org/old-gnu/Manuals/textutils-1.22/html_mono/textutils.html Final step: run the sorted list through uniq to weed out duplicates, producing a unique sorted list of users. ```shell $ who | cut -c1-8 | sort | uniq arnold bill miriam ``` -------------------------------- ### Convert lowercase to uppercase with tr Source: https://ftp.gnu.org/old-gnu/Manuals/textutils-1.22/html_mono/textutils.html Three equivalent ways to convert lowercase to uppercase: explicit ranges, character ranges, and POSIX character classes. ```shell tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ ``` ```shell tr a-z A-Z ``` ```shell tr '[:lower:]' '[:upper:]' ``` -------------------------------- ### BSD idiom: tr -cs A-Za-z0-9 '\012' Source: https://ftp.gnu.org/old-gnu/Manuals/textutils-1.22/html_mono/textutils.html This BSD idiom converts all non-alphanumeric characters to newlines. GNU tr by default pads set2 like BSD, but with --truncate-set1 it behaves like System V, breaking this idiom. ```shell tr -cs A-Za-z0-9 '\012' ``` -------------------------------- ### tr command synopsis Source: https://ftp.gnu.org/old-gnu/Manuals/textutils-1.22/html_mono/textutils.html The general usage form for the tr command: tr [option]... set1 [set2]. It copies standard input to standard output, performing translation, squeezing, deletion, or a combination. ```shell tr [option]... set1 [set2] ``` -------------------------------- ### Spelling checker pipeline step 1: sorted unique words Source: https://ftp.gnu.org/old-gnu/Manuals/textutils-1.22/html_mono/textutils.html First step of spelling checker: generate a sorted list of unique words using sort -u. ```shell $ tr '[A-Z]' '[a-z]' < whats.gnu | tr -cd '[A-Za-z0-9_ \012]' | > tr -s '[ ]' '\012' | sort -u | ... ``` -------------------------------- ### Sort password file on fifth field and numeric user ID Source: https://ftp.gnu.org/old-gnu/Manuals/textutils-1.22/html_mono/textutils.html Sorts /etc/passwd by the fifth field (ignoring leading whitespace) and then by the numeric user ID in field three. The -k 5b,5 specifier applies the 'b' modifier to ignore leading whitespace, and -k 3,3n uses numeric sort on field three. ```shell sort -t : -k 5b,5 -k 3,3n /etc/passwd ``` -------------------------------- ### sort -t : -k 2,2n -k 5.3,5.4: Multi-key sort with field delimiter Source: https://ftp.gnu.org/old-gnu/Manuals/textutils-1.22/html_mono/textutils.html Sorts numerically on the second field, then alphabetically on the third and fourth characters of field five. Uses ':' as the field delimiter. ```shell sort -t : -k 2,2n -k 5.3,5.4 ``` -------------------------------- ### Put all words on lines by themselves Source: https://ftp.gnu.org/old-gnu/Manuals/textutils-1.22/html_mono/textutils.html Converts all non-alphanumeric characters to newlines, then squeezes repeated newlines into a single newline. ```shell tr -cs '[a-zA-Z0-9]' '[\n*]' ``` -------------------------------- ### tr lowercase, punctuation removal, and squeeze blanks pipeline step 3 Source: https://ftp.gnu.org/old-gnu/Manuals/textutils-1.22/html_mono/textutils.html Third step: convert blanks to newlines using tr -s '[ ]' '\012'. The -s option squeezes multiple newline characters into one, avoiding blank lines. The '>' is the shell's secondary prompt. ```shell $ tr '[A-Z]' '[a-z]' < whats.gnu | tr -cd '[A-Za-z0-9_ \012]' | > tr -s '[ ]' '\012' | ... ``` -------------------------------- ### tr aaa xyz and tr a z equivalence Source: https://ftp.gnu.org/old-gnu/Manuals/textutils-1.22/html_mono/textutils.html Shows that when a character appears more than once in set1, only the final corresponding character in set2 is used. Both commands are equivalent. ```shell tr aaa xyz ``` ```shell tr a z ``` -------------------------------- ### Sort password file ignoring leading and trailing whitespace Source: https://ftp.gnu.org/old-gnu/Manuals/textutils-1.22/html_mono/textutils.html Applies the 'b' modifier to the field-end specifier for the first key to ignore both leading and trailing whitespace. Uses the global numeric modifier -n and -k 3,3 for the second key. ```shell sort -t : -n -k 5b,5b -k 3,3 /etc/passwd ``` -------------------------------- ### Squeeze repeated newlines with tr -s Source: https://ftp.gnu.org/old-gnu/Manuals/textutils-1.22/html_mono/textutils.html Converts each sequence of repeated newlines to a single newline. ```shell tr -s '\n' ``` -------------------------------- ### Remove all zero bytes with tr -d Source: https://ftp.gnu.org/old-gnu/Manuals/textutils-1.22/html_mono/textutils.html Deletes all zero bytes from the input using the --delete option. ```shell tr -d '\000' ``` -------------------------------- ### Spelling checker pipeline with comm -23 Source: https://ftp.gnu.org/old-gnu/Manuals/textutils-1.22/html_mono/textutils.html Complete spelling checker: compare sorted unique words with dictionary /usr/lib/ispell/ispell.words using comm -23 - file. The -2 and -3 options eliminate lines only in dictionary and lines in both, leaving words not in dictionary. ```shell $ tr '[A-Z]' '[a-z]' < whats.gnu | tr -cd '[A-Za-z0-9_ \012]' | > tr -s '[ ]' '\012' | sort -u | > comm -23 - /usr/lib/ispell/ispell.words ``` -------------------------------- ### tr lowercase and punctuation removal pipeline step 2 Source: https://ftp.gnu.org/old-gnu/Manuals/textutils-1.22/html_mono/textutils.html Second step: after lowercasing, remove punctuation using tr -cd '[A-Za-z0-9_ \012]'. The complement deletes all characters except letters, digits, underscore, blank, and newline (\012). ```shell $ tr '[A-Z]' '[a-z]' < whats.gnu | tr -cd '[A-Za-z0-9_ \012]' | ... ``` -------------------------------- ### sort -nr: Reverse numeric sort Source: https://ftp.gnu.org/old-gnu/Manuals/textutils-1.22/html_mono/textutils.html Sorts input lines in descending numeric order. The -n option enables numeric comparison and -r reverses the result. ```shell sort -nr ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.