regex, sed, gawk, quiz 2 Flashcards

1
Q

what is a regular expression

A

a description of a pattern of text

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

regex quantifier *

A

zero or more of the preceding characters

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

regex quantifier +

A

one or more of the preceding characters

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

regex quantifier ?

A

zero or one of the preceding characters

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

regex quantifier {min, max}

A

between min and max of preceding characters

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

regex character set [ ]

A

any single character in grouped set

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

regex character set [char - char]

A

any single enclosed range of characters, such as a-z, A-Z, 0-9

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

regex character set [^]

A

complement, excluding the enclosed character, a single character not in a grouped set. For example [^abcd] will match any character that isn’t a, b, c, or d.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

[[:alpha:]]

A

alphabetic characters, [a-zA-Z]
used in regex

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

[[:lower:]]

A

lower case alphabetic characters, [a-z]
used in regex

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

[[:upper:]]

A

upper case alphabetic characters, [A-Z]
used in regex

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

[[:digit:]]

A

digits, [0-9]
used by regex

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

[[:alnum:]]

A

alphanumeric, [a-zA-Z0-9]
used in regex

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

[[:punct:]]

A

punctuation and symbols
used by regex

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

[[:space:]]

A

whitespace (e.g., newline, space, tab)
used in regex

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

regex anchor ^

A

beginning of the line

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

regex anchor $

A

end of the line

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

regex anchor <

A

beginning of word

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

regex anchor >

A

end of word

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

regex special character .

A

any single character, except newline

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

regex special character \

A

escape sequence, escapes the character following it

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

regex special character |

A

logical OR grouping

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

regex special character ()

A

group character set

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

grep

A

standard version of grep that supports basic regular expressions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
egrep (grep –E)
Extended grep that understands extended regexes
26
fgrep (grep –F)
Supports fixed strings for faster performance
27
rgrep (grep –R)
Traverses subdirectories recursively
28
grep option -c
print only a count of matched lines
29
grep option -i
ignore uppercase and lowercase distinctions
30
grep option -l
list all files that contain the specified pattern
31
grep option -n
print matched lines and line numbers
32
grep option -s
work silently -- display nothing except error messages
33
grep option -v
print lines that do not match the pattern
34
sed option -r
makes regexes work better
35
sed option -n
only prints lines specified with print command
36
sed option -f
next argument is the filename containing editing commands
37
sed option -e
next argument is an editing command rather than a filename, useful if multiple commands are specified
38
sed command d
deletes all lines, can be modified such as 6d to delete line 6 or 1,10d to delete line 1 through 10
39
sed command s
substitute, s/regex/new/
40
sed command a
append
41
sed command i
insert
42
sed command c
change
43
sed command p
print: Print command (p) used to force pattern space to be output, useful if -n option has been specified
44
sed command r
read
45
sed command w
write
46
sed command y
transform
47
sed command =
display line number, Line number command (=) writes the current line number before each matched/output line
48
sed command N
append next line to current one
49
sed command q
quit, Syntax: [addr]q – Quit (exit sed) when addr is encountered To print the first 100 lines of a file (like head) sed '100q' filename
50
sed flag n
a number from 1 to 512 indicating which occurrence of pattern should be replaced
51
sed flag g
global, replace all occurrences of pattern in pattern space
52
sed flag p
print contents of pattern space
53
what is gawk
A scripting language used for manipulating data and generating reports – Geared towards working with delimited fields on a line-by-line basis
54
gawk system variable FS
Field separator (default = space), left to right
55
gawk system variable RS
Record separator (default = \n), top to bottom
56
gawk system variable NF
Number of fields in current record
57
gawk system variable NR
Number of the current record
58
gawk system variable OFS
Output field separator (default = space)
59
gawk system variable ORS
Output record separator (default = \n)
60
gawk system variable FILENAME
current filename
61
gawk system variable ARGC/ARGV
Get arguments from command line
62
Which sed command is used to read and insert the contents of a file at the current position in the output?
r
63
Which regex metacharacter is used to specify the end of a line?
'$'
64
What does the regex (abc|def) match?
Either "abc" or "def".
65
Which regex quantifier is used to match one or more occurrences of the preceding element?
'+'
66
In regex, the . (dot) character typically represents _______________
Any single character except a newline.
67
You have a log file and want to find all lines that start with the word "ERROR" followed by a colon. Which grep command would you use?
grep "^ERROR:" logfile.txt
68
You want to count the number of lines in a file that do not contain the word "error." Which grep command would you use?
grep -c -v "error" file.txt
69
How can you make sed edit a file in place (i.e., modify the file directly)?
Use -i option
70
sed option -i
modifies the file in place, basically saves the substitutions
71
What is the purpose of the -n option in sed?
Suppresses automatic printing of pattern space.
72
How can you specify a range of lines to apply a sed command to?
single line numbers separated by a comma (e.g., 1,3).
73
(True / False) The command below replaces the 5th line of a file with a new line of text sed '5s/.*/This is a new line/' input.txt > output.txt
True
74
(True / False) The command below remove all non-empty lines from a file sed '/^$/d' input.txt > output.txt
False
75
Match the regex with the right hand side ^\+\d{1,3}-\d{3}-\d{3}-\d{4}$ (https?|ftp)://[^\s/$.?#].[^\s]* (\d{1,3}\.){3}\d{1,3}
+1 555-555-5555 https://linkedin.com Matches IPv4 addresses such as 192.168.1.1