C.1 Spacing Double-space a fileDouble-space a file, excluding the blank linesTriple-space a fileN-space a fileAdd a blank line before every lineRemove all blank linesRemove all consecutive blank lines, leaving only oneCompress/expand all blank lines into N consecutive linesDouble-space between all wordsRemove all spacing between wordsChange all spacing between words to one spaceInsert a space between all charactersC.2 Numbering Number all lines in a fileNumber only non-empty lines in a fileNumber and print only non-empty lines in a file (drop empty lines)Number all lines but print line numbers only for non-empty linesNumber only lines that match a pattern; print others unmodifiedNumber and print only lines that match a patternNumber all lines but print line numbers only for lines that match a patternNumber all lines in a file using a custom formatPrint the total number of lines in a file (emulate wc -l)Print the number of non-empty lines in a filePrint the number of empty lines in a filePrint the number of lines in a file that match a pattern (emulate grep -c)Number words across all linesNumber words on each individual lineReplace all words with their numeric positionsC.3 Calculations Check if a number is a primePrint the sum of all fields on each linePrint the sum of all fields on all linesShuffle all fields on each lineFind the numerically smallest element (minimum element) on each lineFind the numerically smallest element (minimum element) over all linesFind the numerically largest element (maximum element) on each lineFind the numerically largest element (maximum element) over all linesReplace each field with its absolute valuePrint the total number of fields on each linePrint the total number of fields on each line, followed by the linePrint the total number of fields on all linesPrint the total number of fields that match a patternPrint the total number of lines that match a patternPrint the number πPrint the number ePrint UNIX time (seconds since January 1, 1970, 00:00:00 UTC)Print Greenwich Mean Time and local computer timePrint yesterday’s datePrint the date 14 months, 9 days, and 7 seconds agoCalculate the factorialCalculate the greatest common divisorCalculate the least common multipleGenerate 10 random numbers between 5 and 15 (excluding 15)Generate all permutations of a listGenerate the powersetConvert an IP address to an unsigned integerConvert an unsigned integer to an IP addressC.4 Working with Arrays and Strings Generate and print the alphabetGenerate and print all the strings from “a” to “zz”Create a hex lookup tableGenerate a random eight-character passwordCreate a string of specific lengthCreate an array from a stringCreate a string from the command-line argumentsFind the numeric values for characters in a stringConvert a list of numeric ASCII values into a stringGenerate an array with odd numbers from 1 to 100Generate an array with even numbers from 1 to 100Find the length of a stringFind the number of elements in an arrayC.5 Text Conversion and Substitution ROT13 a stringBase64-encode a stringBase64-decode a stringURL-escape a stringURL-unescape a stringHTML-encode a stringHTML-decode a stringConvert all text to uppercaseConvert all text to lowercaseUppercase only the first letter of each lineInvert the letter caseTitle-case each lineStrip leading whitespace (spaces, tabs) from the beginning of each lineStrip trailing whitespace (spaces, tabs) from the end of each lineStrip whitespace (spaces, tabs) from the beginning and end of each lineConvert UNIX newlines to DOS/Windows newlinesConvert DOS/Windows newlines to UNIX newlinesConvert UNIX newlines to Mac newlinesSubstitute (find and replace) “foo” with “bar” on each lineSubstitute (find and replace) “foo” with “bar” on lines that match “baz”Print paragraphs in reverse orderPrint all lines in reverse orderPrint columns in reverse orderC.6 Selectively Printing and Deleting Lines Print the first line of a file (emulate head -1)Print the first 10 lines of a file (emulate head -10)Print the last line of a file (emulate tail -1)Print the last 10 lines of a file (emulate tail -10)Print only lines that match a regular expressionPrint only lines that do not match a regular expressionPrint every line preceding a line that matches a regular expressionPrint every line following a line that matches a regular expressionPrint lines that match regular expressions AAA and BBB in any orderPrint lines that don’t match regular expressions AAA and BBBPrint lines that match regular expression AAA followed by BBB followed by CCCPrint lines that are at least 80 characters longPrint lines that are fewer than 80 characters longPrint only line 13Print all lines except line 27Print only lines 13, 19, and 67Print all lines from 17 to 30Print all lines between two regular expressions (including the lines that match)Print the longest linePrint the shortest linePrint all lines containing digitsPrint all lines containing only digitsPrint all lines containing only alphabetic charactersPrint every second linePrint every second line, beginning with the second linePrint all repeated lines only oncePrint all unique linesC.7 Useful Regular Expressions Match something that looks like an IP addressTest whether a number is in the range 0 to 255Match an IP addressCheck whether a string looks like an email addressCheck whether a string is a numberCheck whether a word appears in a string twiceIncrease all integers in a string by oneExtract the HTTP User-Agent string from HTTP headersMatch printable ASCII charactersExtract text between two HTML tagsReplace all <b> tags with <strong>Extract all matches from a regular expression