Mastering advanced text processing tools in shell scripting is essential for efficient automation. This chapter covers sed, awk, regular expressions, and pattern matching using grep to manipulate and search text files.
sed and awk Usagesed command do in Linux?
sed is used to perform an in-place edit of a file?
-i-e-r-pawk command in shell scripting?
awk command prints the second column of a file?
awk '{ print $1 }'awk '{ print $2 }'awk '{ print 2 }'awk '{ $2 }'awk, what does $0 represent?
sed commands would delete a line containing the word “error”?
sed '/error/d'sed '/error/c'sed '/error/p'sed '/error/s'awk statement is used to calculate the sum of values in the second column of a file?
awk '{ sum += $2 } END { print sum }'awk '{ sum $2 } END { print sum }'awk '{ $2 += sum } END { print sum }'awk '{ sum = $2 } END { print sum }'-f option do in the awk command?
g flag in the sed substitution command?
awk, which of the following prints the first three columns of a file?
awk '{ print $1, $2, $3 }'awk '{ print $1, $2 }'awk '{ print $1 $2 $3 }'awk '{ print $3 }'.*[]?^$|\a{2,4} match?
aaaa[0-9]\d\w[^a-zA-Z]+ symbol in regular expressions?
grep?
grep -xgrep -Egrep -rgrep -e\w\s\d\t[0-9]{3}[0-9]{3,}\d{3}\d{3,}[^a-z] in a regular expression match?
*+?{}grep command do?
grep to perform a case-insensitive search?
-i-c-l-rlog.txt?
grep error log.txtfind error log.txtsearch error log.txtgrep -w error log.txtgrep command option is used to show the count of matched lines?
-c-n-v-lgrep options shows the line number where the match occurs?
-n-c-v-lgrep "data" *grep -r "data" *grep -l "data" *grep -f "data" *-v option in grep do?
grep command option is used to show only the filenames containing the match?
-l-v-c-ngrep -r?
grep options would invert the match, showing lines that do not contain the pattern?
-v-n-i-l| Qno | Answer |
|---|---|
| 1 | b) Stream edit text in a file |
| 2 | a) -i |
| 3 | c) Process and analyze text files and streams |
| 4 | b) awk '{ print $2 }' |
| 5 | c) The entire record/line |
| 6 | a) sed '/error/d' |
| 7 | a) awk '{ sum += $2 } END { print sum }' |
| 8 | b) Executes a script from a file |
| 9 | b) Substitute all occurrences in the line |
| 10 | a) awk '{ print $1, $2, $3 }' |
| 11 | a) . |
| 12 | a) ^ |
| 13 | c) Between 2 and 4 occurrences of a |
| 14 | a) [0-9] |
| 15 | b) Matches 1 or more occurrences of the previous character |
| 16 | b) grep -E |
| 17 | b) \s |
| 18 | a) [0-9]{3} |
| 19 | b) Any character except lowercase letters |
| 20 | c) ? |
| 21 | b) Searches for patterns in files |
| 22 | a) -i |
| 23 | a) grep error log.txt |
| 24 | a) -c |
| 25 | a) -n |
| 26 | b) grep -r "data" * |
| 27 | b) Shows non-matching lines |
| 28 | a) -l |
| 29 | a) To search for a pattern recursively in directories |
| 30 | a) -v |