LPIC-1 Shells, Scripting and Data Management Practice Question
Which TWO of the following commands can be used to replace text patterns in a file and output the result?
⚠ Common exam trap
Test-takers frequently confuse grep's pattern-matching capability with text replacement, assuming it can modify content, when in fact grep only filters lines and does not alter or output transformed text.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
awk
awk is a powerful text-processing tool that can perform pattern matching and replacement using its sub() and gsub() functions, making it suitable for replacing text patterns in a file and outputting the result. It operates on a per-record (line) basis and supports regular expressions, allowing complex substitutions directly within the script.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
awk
Why this is correct
awk can use gsub() or sub() for replacement.
- ✗
grep
Why it's wrong here
grep only searches, does not replace.
- ✓
sed
Why this is correct
sed can perform search and replace with s command.
- ✗
tr
Why it's wrong here
tr translates characters, not patterns.
- ✗
cut
Why it's wrong here
cut extracts columns, does not replace.
Go deeper
Related to this question
About these practice questions
One of 527 original LPIC-1 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This LPIC-1 practice question is part of Courseiva's free LPI certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the LPIC-1 exam.