Text processing Flashcards

1
Q

What is the ‘cut’ command used for?

A

Used for extracting text by splitting lines on delimiters/byte positions/character patterns

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

How can you get the nth character from each line with ‘cut’?

A

cut -c<n> <filename></filename></n>

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

How can you get the multiple characters from each line with ‘cut’?

A

cut -c1,3,4 <filename> (returns 1st 3rd and 4th characters)</filename>

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

How do you get a range of characters from each line using ‘cut’?

A

cut -c1-3,6-10 <filename></filename>

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

How do you get a range of bytes from each line using ‘cut’?

A

cut -b1-8 <filename> (first 8 bytes)</filename>

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

How can you split lines into columns on a colon (:) delimiter and select the 5th column using ‘cut’?

A

cut -d: -f 5 <filename></filename>

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

How can you use ‘cut’ on the output of another command?

A

<command></command>

[OPTIONS] | cut [OPTIONS] <filename></filename>

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

What is the ‘awk’ command used for?

A

Text processing utility/language used to extract text from files or command output

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

How do you out space separated columns lines of text using ‘awk’?

A

awk ‘{print $1}’ <filename> ($n is the column number)</filename>

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

How can you get multiple columns using ‘awk’?

A

awk ‘{print $1,$2,$3}’ <filename></filename>

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

How can you get the last column using ‘awk’?

A

awk ‘{print $NF}’ <filename></filename>

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

How can you search for text using ‘awk’?

A

awk ‘/<text_search>/ {print}' <filename></filename></text_search>

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

How can you split text on a delimiter using ‘awk’?

A

awk -F<delimiter> '{print $1}' <filename></filename></delimiter>

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

How can you replace text using ‘awk’?

A

echo “One” | awk ‘{$1=”Two”; print $0}’ (replaces One with Two)

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

How can you get all file lines longer than n bytes with ‘awk’?

A

cat <filename> | awk 'length($0) > <n>'</n></filename>

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

Detail the syntax of an ‘if’ statement in ‘awk’

A

ls -l | awk ‘{if($9 == “username”) print $0;}’ - ‘{if(something) something $n;}’

17
Q

How do you print the number of fields per line using ‘awk’?

A

awk ‘{print NF}’

18
Q

What is the command ‘grep’ used for?

A

Advanced pattern matching tool for finding text within files and output

19
Q

What does ‘grep’ stand for?

A

Global Regular Expression Print

20
Q

What is the basic syntax of ‘grep’?

A

grep <search_term> <filename></filename></search_term>

21
Q

How can count occurrences of a search term in ‘grep’?

A

grep -c <search_term> <filename></filename></search_term>

22
Q

How can you ignore case in the search term in ‘grep’?

A

grep -i <search_term> <filename></filename></search_term>

23
Q

How can get matched line numbers in ‘grep’?

A

grep -n <search_term> <filename></filename></search_term>

24
Q

How can get all non-matched lines in ‘grep’?

A

grep -v <search_term> <filename></filename></search_term>

25
Q

How can use ‘grep’ on the output of another command?

A

<command></command>

[OPTIONS] | grep <search_term></search_term>

26
Q

How can you search for multiple terms with ‘egrep’?

A

egrep -i “<keyword1>|<keyword2>" <filename></filename></keyword2></keyword1>

27
Q

What is the ‘sort’ command used for?

A

Sorting text in alphabetical order

28
Q

What is the ‘uniq’ command used for?

A

Filtering out lines with repeated text

29
Q

What is the basic syntax of ‘sort’?

A

sort <filename> or <command></command> [OPTIONS] | sort</filename>

30
Q

How do list in reverse order using ‘sort’?

A

sort -r <filename></filename>

31
Q

How can you order by space-separated column number using ‘sort’?

A

sort -k2 <filename></filename>

32
Q

Detail a limitation of ‘uniq’ that means it will still sometimes display duplicate lines.

A

Input to ‘uniq’ must be sorted. ‘uniq’ does not guarantee that duplicates are removed unless they are adjacent

33
Q

How are ‘sort’ and ‘uniq’ used together?

A

sort <filename> | uniq</filename>

34
Q

How can you display duplicate counts with ‘uniq’?

A

sort <filename> | uniq -c</filename>

35
Q

How can you display only duplicated text with ‘uniq’?

A