Text processing Flashcards

(40 cards)

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 -cn filename

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)

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

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)

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

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 [OPTIONS] | cut [OPTIONS] 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)

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

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

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</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</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’

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;}’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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

21
Q

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

A

grep -c search_term filename

22
Q

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

A

grep -i search_term filename

23
Q

How can you get matched line numbers in ‘grep’?

A

grep -n search_term filename

24
Q

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

A

grep -v search_term filename

25
How can use 'grep' on the output of another command?
command [OPTIONS] | grep search_term
26
How can you search for multiple terms with 'egrep'?
egrep -i "keyword1|keyword2"
27
What is the 'sort' command used for?
Sorting text in alphabetical order
28
What is the 'uniq' command used for?
Filtering out lines with repeated text
29
What is the basic syntax of 'sort'?
sort filename or command [OPTIONS] | sort
30
How do list in reverse order using 'sort'?
sort -r filename
31
How can you order by space-separated column number using 'sort'?
sort -k2 filename
32
Detail a limitation of 'uniq' that means it will still sometimes display duplicate lines.
Input to 'uniq' must be sorted. 'uniq' does not guarantee that duplicates are removed unless they are adjacent
33
How are 'sort' and 'uniq' used together?
sort filename | uniq
34
How can you display duplicate counts with 'uniq'?
sort filename> | uniq -c
35
How can you display only duplicated text with 'uniq'?
sort filename | uniq -d
36
What is the 'wc' command used for?
Counting lines, words, or bytes of an input stream
37
What is the standard output of 'wc' when a file is passed?
lines words bytes filename
38
How can you print line count using 'wc'?
wc -l filename
39
How can you print word count using 'wc'?
wc -w filename
40
How can you print byte count using 'wc'?
wc -c filename