Pattern matching and searching Flashcards

1
Q

Which command enables users to search for strings or patterns within the content of a file?

A

grep

grep [-options] pattern filename

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

What does “grep -i” mean?

grep –i hall /student_files/day1/grepFile

A

grep –i: ignore case

Both upper or lower case is fine.

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

What does “grep -n” mean?

grep –n hall /student_files/day1/grepFile

A

grep –n: gives you the line number

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

What does “grep -v” mean?

grep –v hall /student_files/day1/grepFile

A

grep –v: returns everything but what the matcher

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

What does “grep -w” mean?

grep –w hall /student_files/day1/grepFile

A

grep –w: match the whole word

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

What does “grep -c” mean?

grep –c hall /student_files/day1/grepFile

A

grep –c: count the number of lines matching

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

What are Literal and meta character(s)?

A

Literal: “coffee”
Metacharacter: [ ] ! * . ? $ \ { } ( )
Escape sequence: \

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

Metacharacters

A

^: Match at start of line

$: Match at the end of line

. : Match a single character

*: Match zero or more occurrences of the preceding character

.*: Match with any number of characters

: Escape the metacharacter and treat them as a literal

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

What does the following command mean?

grep ‘^[0-9]’ /student_files/day1/grepFile

A

grep ‘^[0-9]’ /student_files/day1/grepFile

^: Match at start of line
[ ]: Match anything in the [ ] for 1 character position

So it means: Within the grepFile, find any line that starts with 0-9.

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

What does the following command mean?

grep ‘6.’ /student_files/day1/grepFile

A

grep ‘6.’ /student_files/day1/grepFile

. : Match a single character

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

What does the following command mean?

grep ‘6.’ /student_files/day1/grepFile

A

grep ‘6.’ /student_files/day1/grepFile

: Escape the metacharacter and treat them as a literal

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

What does the following command mean?

grep ‘192.*0’ /student_files/day1/grepFile

A

grep ‘192.*0’ /student_files/day1/grepFile

.*: Match with any number of characters

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

What does the following command mean?

grep ‘192*0’ /student_files/day1/grepFile

A

grep ‘192*0’ /student_files/day1/grepFile

*: Match zero or more occurrences of the preceding character

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

What does the “find” command do?

A

find [where to search] [what to search for] [action]

The find command enable users to locate files in the File System.

find searches through the directory tree recursively, locates the files and applies an optional action to the files found

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