Text processing Flashcards

1
Q

use a command to prints second, fifth and seventh character from each line of the file.

A

$ cut -c 2,5,7 name.txt

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

command prints starting from first character to end.
command prints starting position to the fifth character.

A

$ cut -c 1- state.txt

$ cut -c -5 state.txt

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

when space is used as a field separator or delimiter to print words of each line.

A

$ cut -d “ “ -f 1 state.txt

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

use a command to print the 1th and 4th column (field) in a file.

A

$ awk ‘{print $1,$4}’ employee.txt

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

in awk print the first item along with the row number separated with ” – “ from each line.

A

$ awk ‘{print NR “- “ $1 }’ geeksforgeeks.txt

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

use a command for Printing lines with more than 10 characters.

A

$ awk ‘length($0) > 10’ geeksforgeeks.txt

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

To print the squares of first numbers from 1 to n say 6 in awk.

A

$ awk ‘BEGIN { for(i=1;i<=6;i++) print “square of”, i, “is”,i*i; }’

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

use a search command to do a Case insensitive search.

A

$grep -i “UNix” geekfile.txt

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

use a command to search and to Displaying only the matched pattern (word) you want to search in a file.

A

$ grep -o “unix” geekfile.txt

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

use a command to Show line number while displaying the output using grep.

A

$ grep -n “unix” geekfile.txt

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

use a command to display the lines that are not matching with the specified search string pattern.

A

$ grep -n “unix” geekfile.txt

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

use 2 commands to search for multiple strings (words) in a file.

A

$grep –e “Agarwal” –e “Aggarwal” –e “Agrawal” geekfile.txt

egrep -i milo|dandi|denne geekfile.txt

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

use 2 methods to sort a file and to write the output to a new file.

A

$ sort inputfile.txt > filename.txt
$ sort -o filename.txt inputfile.txt

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

use a command option to Sort In Reverse Order:

A

$ sort -r inputfile.txt

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

use a command option to sort the file with numeric data present inside.

A

$ sort -n filename.txt

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

sort a file with numeric data in reverse order.

A

$ sort -nr filename.txt
(combination of 2 options)

17
Q

Use a command option to sorting a table on the basis of any column number. Also if that column is numeric.

A

$ sort -k 2 employee.txt
$ sort -k 2n employee.txt

18
Q

use a command option to sort and remove duplicates .

A

$ sort -u filename.txt

19
Q

use a command option to sort by month

A

$ sort -M filename.txt

20
Q

use a command option prints the number of words present in a file.

A

wc -w filename.txt

21
Q

use a command to convert lower case characters to upper case.

A

tr [a-z] [A-Z] < filename.txt
tr [:lower:] [:upper:] < filename.txt
$ cat greekfile | tr [a-z] [A-Z]

22
Q

use a command to translate white-space characters to tabs.

A

tr [:space:] “\t” <filename.txt
tr “ “ “\t” <filename.txt

23
Q

use a command to translate braces into parenthesis and redirect it to another file.

A

$ tr “{}” “()” <greekfile>newfile.txt</greekfile>

24
Q

use a command to squeeze a sequence of repetitive characters.

A

$ echo “Welcome To GeeksforGeeks” | tr -s “ “
tr -s “ “ <filename.txt

25
Q

use a command to delete specified characters.

A

$ echo “Welcome To GeeksforGeeks” | tr -d …. tr -d W
$ tr -d W <filename.txt

26
Q
A