Brainscape Linux Flashcards
how do you specify a delimiter, also, what is the default delimiter if not specified
-d, –delimiter (e.g. “cut -d ‘,’”) tab is default
what are the three ways you can specify what is to be sliced
-b, –bytes -c, –characters -f, –fields
how do you select the inverse the fields you specify (e.g. everything but)
–complement
how do you ignore any lines that don’t contain the delimiter character
-s, –only-delimited
how do you specify a different delimiter for the OUTPUT of what is cut
–output-delimiter=STRING
how do you specify the following: from N to end of line from beginning of line to M from N to M columns 2 through four and column 6
N- -M N-M 2-4,6
are ranges inclusive or exclusive
ranges are inclusive
what do fields begin counting from
fields begin at at “1” for cut
using sed, double space a file
sed G
using sed, double space a file that already has blank lines in it (the output should have no more than one blank line between lines of text)
sed ‘/^$/d;G’ (delete any lines that meet the address flag of being blank, and double space file)
using sed, undo double-spacing (assuming even-numbered lines are always blank)
sed ‘n;d’
using sed, convert Unix format (LF) to DOS format (CRLF)
sed ‘s/$/\r/’
using sed, delete leading whitespace (tabs, spaces) from beginning of each line
sed ‘s/^[ \t]*//’
using sed, delete trailing whitespace (tabs, spaces) from each end of line
sed ‘s/[ \t]*$//’
using sed, replace only the first instance in each line
sed ‘s/foo/bar/’
using sed, replace only the fourth instance in each line
sed ‘s/foo/bar/4’
using sed, replace all instances in a line
sed ‘s/foo/bar/g’
using sed, substitute “foo” with “bar” ONLY for lines which contain “baz”
sed ‘/baz/s/foo/bar/g’
using sed, substitute “foo” with “bar” EXCEPT for lines which contain “baz”
sed ‘/baz/!s/foo/bar/g’
using sed, change “scarlet” or “ruby” or “puce” to “red”
sed ‘s/scarlet|ruby|puce/red/g’
using sed, add a blank line every 5 lines (after lines 5, 10, 15, 20, etc.)
sed ‘1~5G’
using sed, print the first 10 lines of file (emulate “head”), print the first line of the file
sed 10q (remember that “q” will print the current pattern space before quitting sed q)
using sed, print only lines which match regular expression (emulate “grep”)
sed -n ‘/regexp/p’ OR sed ‘/regexp/!d’
using sed, print only lines that do NOT match regexp (emulate “grep -v”)
sed -n ‘/regexp/!p’ OR sed ‘/regexp/d’
using sed, print all of file EXCEPT section between 2 regular expressions
sed ‘/Iowa/,/Montana/d’
using sed, delete lines matching pattern
sed ‘/pattern/d’
using sed, add a leading angle bracket and space to each line (quote a message)
sed ‘s/^/> /’
using sed, delete leading angle bracket & space from each line (unquote a message)
sed ‘s/^> //’
sed command: q
print current pattern space and quit
sed command: d
delete current pattern space and immediately start next cycle
sed command: p
print the current pattern space (usually used in conjunction with “-n” option)
sed command: n
print pattern space (or not, if auto-print is disabled), and replace the pattern space with the next line of input (mnemonic: “next”)
sed command: { and }
groups of commands can be enclosed between curly braces–this can be helpful when using addresses for multiple commands
sed command: “a text”
append “text” after a line (at the end of the cycle), ignoring leading whitespace (text to add is read to the end of the line)
sed command: “i text”
same as “a text”, but inserts text BEFORE the line
sed command: “c text”
change text (same as “a text”, except that this one deletes lines matching the address or address-range, and puts “text” in their place)
sed command: =
print the current line number, with a trailing newline
sed command: “r filename”
read filename and insert at end of cycle
sed command: “w filename”
write the pattern space to filename (file will be created (or overwritten) at the beginning of the script, and all “w” commands pointed to the same filename will be appended to the file throughout the script)
sed command: D
delete text in the pattern space up to the first newline, and start a new cycle without reading a new line of input (if only one line in pattern space, works just like lower-case “d”)