Sed MCQs and Answers with Explanation: Sed (stream editor) is a powerful Unix utility used for parsing and transforming text. It allows users to perform complex text manipulations, including find and replace operations, regular expression matching, and file processing. As Sed remains a popular tool for system administration and text processing, it is essential to have a good understanding of its utility and its features. The Sed MCQ questions included in this article can be of great assistance in testing your knowledge and enhancing it at the same time.
Sed MCQs and Answers
The Sed Multiple Choice Questions that are provided in this article cover various aspects of the utility, including basic commands, regular expressions, and file processing. Whether you are a beginner or an experienced user, these Sed MCQs with Answers will challenge your understanding of Sed and help you identify areas where you need to improve. Now without any delay move on to the next section and attempt the Sed Quiz to understand the Sed concept.
Sed Multiple Choice Questions
Name | Sed |
Exam Type | MCQ (Multiple Choice Questions) |
Category | Technical Quiz |
Mode of Quiz | Online |
Top 48 Sed MCQs with Answers | Sed Quiz
1. What is Sed short for?
a) Stream Editor
b) String Editor
c) System Editor
d) Syntax Editor
Answer: a) Stream editor
Explanation: Sed is a stream editor that can be used to perform various text transformations on an input stream.
2. What is the purpose of Sed?
a) To create new files
b) To edit existing files
c) To delete files
d) To move files
Answer: b) To edit existing files
Explanation: Sed is primarily used to edit existing files by performing various text transformations such as search and replace, deletion, insertion, etc.
3. Which command is used to substitute the first occurrence of a pattern in Sed?
a) s
b) g
c) p
d) a
Answer: a) s
Explanation: The “s” command is used to substitute the first occurrence of a pattern with a replacement in Sed.
4. Which option is used to print the lines that do not match a pattern in Sed?
a) -n
b) -e
c) -v
d) -i
Answer: c) -v
Explanation: The “-v” option is used to print the lines that do not match a pattern in Sed.
5. Which command is used to append a line after a pattern in Sed?
a) a
b) i
c) c
d) d
Answer: a) a
Explanation: The “a” command is used to append a line after a pattern in Sed.
6. Which command is used to delete a line in Sed?
a) d
b) a
c) i
d) c
Answer: a) d
Explanation: The “d” command is used to delete a line in Sed.
7. Which command is used to insert a line before a pattern in Sed?
a) i
b) a
c) c
d) d
Answer: a) i
Explanation: The “i” command is used to insert a line before a pattern in Sed.
8. Which option is used to perform a case-insensitive search in Sed?
a) -i
b) -c
c) -n
d) -s
Answer: a) -i
Explanation: The “-i” option is used to perform a case-insensitive search in Sed.
9. Which command is used to substitute all occurrences of a pattern in Sed?
a) s
b) g
c) p
d) a
Answer: b) g
Explanation: The “g” command is used to substitute all occurrences of a pattern with a replacement in Sed.
10. Which command is used to print a specific line number in Sed?
a) p
b) n
c) q
d) l
Answer: b) n
Explanation: The “n” command is used to print a specific line number in Sed.
11. Which option is used to perform an in-place editing in Sed?
a) -i
b) -e
c) -p
d) -v
Answer: a) -i
Explanation: The “-i” option is used to perform an in-place editing in Sed.
12. Which command is used to print the last line of a file in Sed?
a) $p
b) 1p
c) /^$/p
d) /./p
Answer: a) $p
Explanation: The “$p” command is used to print the last line of a file in Sed.
13. Which command is used to join two consecutive lines in Sed?
a) j
b) s
c) d
d) i
Answer: a) j
Explanation: The “j” command is used to join two consecutive lines in Sed.
14. Which command is used to print only the lines that match a pattern in Sed?
a) p
b) n
c) q
d) /pattern/p
Answer: d) /pattern/p
Explanation: The “/pattern/p” command is used to print only the lines that match a pattern in Sed.
15. Which command is used to print the first 10 lines of a file in Sed?
a) 10p
b) $p
c) /^$/p
d) /./p
Answer: a) 10p
Explanation: The “10p” command is used to print the first 10 lines of a file in Sed.
16. Which command is used to print a range of lines in Sed?
a) :p
b) :n
c) :1,10p
d) :1,$p
Answer: d) :1,$p
Explanation: The “:1,$p” command is used to print a range of lines from line 1 to the last line of the file in Sed.
17. Which option is used to display the version information of Sed?
a) –version
b) –help
c) –verbose
d) –quiet
Answer: a) –version
Explanation: The “–version” option is used to display the version information of Sed.
18. Which option is used to specify a script file in Sed?
a) -s
b) -e
c) -f
d) -i
Answer: c) -f
Explanation: The “-f” option is used to specify a script file in Sed.
19. Which command is used to delete all blank lines in Sed?
a) /^$/d
b) /./d
c) /^$/p
d) /./p
Answer: a) /^$/d
Explanation: The “/^$/d” command is used to delete all blank lines in Sed.
20. Which option is used to enable extended regular expressions in Sed?
a) -E
b) -e
c) -r
d) -i
Answer: a) -E
Explanation: The “-E” option is used to enable extended regular expressions in Sed.
21. Which command is used to replace a string with another string in Sed?
a) s
b) g
c) p
d) a
Answer: a) s
Explanation: The “s” command is used to replace a string with another string in Sed.
22. Which option is used to suppress automatic printing of the pattern space in Sed?
a) -n
b) -e
c) -p
d) -u
Answer: a) -n
Explanation: The “-n” option is used to suppress automatic printing of the pattern space in Sed.
23. Which command is used to copy a line to the hold space in Sed?
a) h
b) H
c) g
d) G
Answer: a) h
Explanation: The “h” command is used to copy a line to the hold space in Sed.
24. Which command is used to copy the hold space to the pattern space in Sed?
a) g
b) G
c) h
d) H
Answer: a) g
Explanation: The “g” command is used to copy the hold space to the pattern space in Sed.
25. Which command is used to append the contents of a file after a specific line in Sed?
a) a
b) b
c) r
d) i
Answer: c) r
Explanation: The “r” command is used to append the contents of a file after a specific line in Sed.
26. Which option is used to edit the file in place in Sed?
a) -i
b) -e
c) -f
d) -s
Answer: a) -i
Explanation: The “-i” option is used to edit the file in place in Sed.
27. Which command is used to delete a range of lines in Sed?
a) :d
b) :n
c) :1,10d
d) :1,$d
Answer: d) :1,$d
Explanation: The “:1,$d” command is used to delete a range of lines from line 1 to the last line of the file in Sed.
28. Which option is used to specify a backup file extension in Sed?
a) -i
b) -e
c) -f
d) -s
Answer: a) -i
Explanation: The “-i” option is used to specify a backup file extension in Sed.
29. Which command is used to delete a specific line in Sed?
a) d
b) s
c) p
d) a
Answer: a) d
Explanation: The “d” command is used to delete a specific line in Sed.
30. Which command is used to substitute a pattern with a string in a specific range of lines in Sed?
a) :s/pattern/string/1,10
b) :s/pattern/string/g
c) :s/pattern/string/1,$
d) :s/pattern/string/
Answer: a) :s/pattern/string/1,10
Explanation: The “:s/pattern/string/1,10” command is used to substitute a pattern with a string in a specific range of lines from line 1 to line 10 in Sed.
31. Which command is used to insert a line before a specific line in Sed?
a) i
b) a
c) r
d) s
Answer: a) i
Explanation: The “i” command is used to insert a line before a specific line in Sed.
32. Which command is used to replace the contents of the pattern space with the contents of the hold space in Sed?
a) g
b) G
c) h
d) H
Answer: b) G
Explanation: The “G” command is used to replace the contents of the pattern space with the contents of the hold space in Sed.
33. Which command is used to print the line number before each line in Sed?
a) =
b) #
c) ^
d) %
Answer: a) =
Explanation: The “=” command is used to print the line number before each line in Sed.
34. Which command is used to replace all occurrences of a pattern with a string in Sed?
a) s
b) g
c) p
d) a
Answer: b) g
Explanation: The “g” command is used to replace all occurrences of a pattern with a string in Sed.
35. Which command is used to append a line after a specific line in Sed?
a) i
b) a
c) r
d) s
Answer: b) a
Explanation: The “a” command is used to append a line after a specific line in Sed.
36. Which command is used to print the current line number in Sed?
a) =
b) #
c) ^
d) %
Answer: d) %
Explanation: The “%” command is used to print the current line number in Sed.
37. Which option is used to suppress automatic printing in Sed?
a) -n
b) -e
c) -f
d) -i
Answer: a) -n
Explanation: The “-n” option is used to suppress automatic printing in Sed.
38. Which command is used to delete all lines that do not match a pattern in Sed?
a) /pattern/d
b) /pattern/!d
c) /pattern/g
d) /pattern/s
Answer: b) /pattern/!d
Explanation: The “/pattern/!d” command is used to delete all lines that do not match a pattern in Sed.
39. Which option is used to specify a command file in Sed?
a) -e
b) -f
c) -i
d) -n
Answer: b) -f
Explanation: The “-f” option is used to specify a command file in Sed.
40. Which command is used to print the current line in Sed?
a) p
b) n
c) q
d) r
Answer: a) p
Explanation: The “p” command is used to print the current line in Sed.
41. Which command is used to append a file after a specific line in Sed?
a) i
b) a
c) r
d) s
Answer: c) r
Explanation: The “r” command is used to append a file after a specific line in Sed.
42. Which command is used to replace all occurrences of a pattern with a string in a specific range of lines in Sed?
a) :s/pattern/string/1,10
b) :s/pattern/string/g
c) :s/pattern/string/1,$
d) :s/pattern/string/
Answer: c) :s/pattern/string/1,$
Explanation: The “:s/pattern/string/1,$” command is used to replace all occurrences of a pattern with a string in a specific range of lines from line 1 to the last line of the file in Sed.
43. Which command is used to substitute the nth occurrence of a pattern with a string in Sed?
a) :s/pattern/string/n
b) :s/pattern/string/gn
c) :s/pattern/string/1,n
d) :s/pattern/string/n$
Answer: a) :s/pattern/string/n
Explanation: The “:s/pattern/string/n” command is used to substitute the nth occurrence of a pattern with a string in Sed.
44. Which option is used to specify a delimiter in a Sed command?
a) -d
b) -e
c) -f
d) -i
Answer: a) -d
Explanation: The “-d” option is used to specify a delimiter in a Sed command.
45. Which command is used to replace a string in a specific line in Sed?
a) :s/pattern/string/1
b) :s/pattern/string/g
c) :s/pattern/string/1$
d) :s/pattern/string/
Answer: a) :s/pattern/string/1
Explanation: The “:s/pattern/string/1” command is used to replace a string in the first line of the file in Sed.
46. Which command is used to append a string before a specific line in Sed?
a) i
b) a
c) r
d) s
Answer: a) i
Explanation: The “i” command is used to append a string before a specific line in Sed.
47. Which command is used to move a range of lines to a specific line in Sed?
a) :m10,20 30
b) :m10,20 /pattern/
c) :m10,20 $
d) :m10,20 10$
Answer: a) :m10,20 30
Explanation: The “:m10,20 30” command is used to move a range of lines from line 10 to line 20 to line 30 in Sed.
48. Which option is used to edit a file in place with Sed?
a) -i
b) -e
c) -f
d) -n
Answer: a) -i
Explanation: The “-i” option is used to edit a file in place with Sed.
The set of Sed MCQ questions and answers provided in this article can be a valuable resource for individuals looking to enhance their proficiency in this utility. This Sed quiz covers various aspects of Sed, enabling you to identify areas where you need to improve and enhance your skills in text manipulation and file processing on Unix systems. If you find this article helpful, keep checking our Freshersnow website to receive more such articles regularly.