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
Q

egrep (grep –E)

A

Extended grep that understands extended regexes

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

fgrep (grep –F)

A

Supports fixed strings for faster performance

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

rgrep (grep –R)

A

Traverses subdirectories recursively

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

grep option -c

A

print only a count of matched lines

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

grep option -i

A

ignore uppercase and lowercase distinctions

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

grep option -l

A

list all files that contain the specified pattern

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

grep option -n

A

print matched lines and line numbers

32
Q

grep option -s

A

work silently – display nothing except error messages

33
Q

grep option -v

A

print lines that do not match the pattern

34
Q

sed option -r

A

makes regexes work better

35
Q

sed option -n

A

only prints lines specified with print command

36
Q

sed option -f

A

next argument is the filename containing editing commands

37
Q

sed option -e

A

next argument is an editing command rather than a filename, useful if multiple commands are specified

38
Q

sed command d

A

deletes all lines, can be modified such as 6d to delete line 6 or 1,10d to delete line 1 through 10

39
Q

sed command s

A

substitute, s/regex/new/

40
Q

sed command a

A

append

41
Q

sed command i

A

insert

42
Q

sed command c

A

change

43
Q

sed command p

A

print:
Print command (p) used to force pattern space to be output,
useful if -n option has been specified

44
Q

sed command r

A

read

45
Q

sed command w

A

write

46
Q

sed command y

A

transform

47
Q

sed command =

A

display line number, Line number command (=) writes the current line number before each matched/output line

48
Q

sed command N

A

append next line to current one

49
Q

sed command q

A

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
Q

sed flag n

A

a number from 1 to 512 indicating which occurrence of pattern
should be replaced

51
Q

sed flag g

A

global, replace all occurrences of pattern in pattern space

52
Q

sed flag p

A

print contents of pattern space

53
Q

what is gawk

A

A scripting language used for manipulating data and generating reports
– Geared towards working with delimited fields on a line-by-line basis

54
Q

gawk system variable FS

A

Field separator (default = space), left to right

55
Q

gawk system variable RS

A

Record separator (default = \n), top to bottom

56
Q

gawk system variable NF

A

Number of fields in current record

57
Q

gawk system variable NR

A

Number of the current record

58
Q

gawk system variable OFS

A

Output field separator (default = space)

59
Q

gawk system variable ORS

A

Output record separator (default = \n)

60
Q

gawk system variable FILENAME

A

current filename

61
Q

gawk system variable ARGC/ARGV

A

Get arguments from command line

62
Q

Which sed command is used to read and insert the contents of a file at the current position in the output?

A

r

63
Q

Which regex metacharacter is used to specify the end of a line?

A

’$’

64
Q

What does the regex (abc|def) match?

A

Either “abc” or “def”.

65
Q

Which regex quantifier is used to match one or more occurrences of the preceding element?

A

’+’

66
Q

In regex, the . (dot) character typically represents _______________

A

Any single character except a newline.

67
Q

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?

A

grep “^ERROR:” logfile.txt

68
Q

You want to count the number of lines in a file that do not contain the word “error.” Which grep command would you use?

A

grep -c -v “error” file.txt

69
Q

How can you make sed edit a file in place (i.e., modify the file directly)?

A

Use -i option

70
Q

sed option -i

A

modifies the file in place, basically saves the substitutions

71
Q

What is the purpose of the -n option in sed?

A

Suppresses automatic printing of pattern space.

72
Q

How can you specify a range of lines to apply a sed command to?

A

single line numbers separated by a comma (e.g., 1,3).

73
Q

(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

A

True

74
Q

(True / False) The command below remove all non-empty lines from a file

sed ‘/^$/d’ input.txt > output.txt

A

False

75
Q

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}

A

+1 555-555-5555

https://linkedin.com

Matches IPv4 addresses such as 192.168.1.1