Brainscape Linux Flashcards
(102 cards)
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’