Professional Documents
Culture Documents
DESCRIPTION
grep searches the named input FILEs for lines containing a match to
the given PATTERN.
-i, --ignore-case
Ignore case distinctions in both the PATTERN and the input
files.
-n, --line-number
Prefix each line of output with the 1-based line number
within its input file.
-c, --count
Suppress normal output; instead print a count of matching
lines for each input file.
2
The grep command (remember)
I Display lines that contain the string Married
4
The grep patterns (regular expressions)
5
The grep patterns (regular expressions)
I Lines containing “th” preceded by any numeric character
7
Escaping meta-characters
8
Splice-junction Gene Sequences data set
wget https://archive.ics.uci.edu/ml/machine-learning-databases/
molecular-biology/splice-junction-gene-sequences/splice.data
9
Grouping
10
Extended regular expressions
11
Extended regular expressions - Alternation
12
Extended regular expressions - Quantifiers
13
Extended regular expressions - Quantifiers
14
Exercises
15
Expansions
16
Arithmetic expansion
$((oper))
where oper is any operation with integer numbers, are expanded
by the shell to their corresponding value
I Examples:
echo $((4+3))
echo $((10/3))
17
Brace expansion
{list}
where list is a comma separated list of strings, are expanded by the
shell as follows
I Print the list A B C
echo {A,B,C}
I Print the list horse home hope horoscope
echo ho{rs,m,p,roscop}e
18
Brace expansion
{x..y}
where x and y are integer numbers or chars, are expanded by the
shell in a similar way
I Print the list a b ... z
echo {a..z}
I Print the list 3 4 5 6 7
echo {3..7}
19
Brace expansion
echo {z..a}
echo {9..1}
I Brace expansions can be nested
echo {X{1,2},Y{3,4}}
echo {X,Y}{1..4}
20
Exercises
21
Command and process substitution
22
Command substitution
$(command)
I Print with echo the output of ls
echo $(ls)
I Make directories with the names of the unique values in the
4th column of adult.data
mkdir $(cut -d "," -f 4 adult.data | sort | uniq)
23
Process substitution
command <(list)
Executes all the commands in list saving the output to a file, which
is then used as input to command
command >(list)
Executes command saving the output to a file, which is then used
as input to list
24
Process substitution
25
Exercises
26