
In the final part of this Linux command series, we focus on advanced text editing and data manipulation tools that are widely used in real-world Linux environments. These commands help you edit files faster, analyze data efficiently, and automate text-based tasks with confidence.This guide covers practical usage of vim, advanced sed operations, powerful awk patterns, and supporting tools like cut, sort, uniq, and tr. These are essential skills for system administrators, DevOps engineers, and anyone working heavily with logs, CSV files, or configuration files.
Command Summary
| Command | Description |
|---|---|
vim <file> | Open a file using the Vim editor |
i | Switch to insert mode |
Esc | Return to command mode |
:w | Save the file |
:q | Quit Vim |
:wq | Save and quit |
:q! | Quit without saving changes |
yy | Copy the current line |
p | Paste copied content |
dd | Delete the current line |
u | Undo the last action |
Ctrl+r | Redo the last undone action |
/word | Search forward for a word |
?word | Search backward for a word |
:s/old/new | Replace first occurrence in a line |
:s/old/new/g | Replace all occurrences in a line |
sed -n '5,10p' | Print specific line ranges |
sed 's/old/new/g' | Replace text in output |
sed -i | Edit file content in-place |
awk '{print $1}' | Print first column |
awk '/pattern/' | Filter lines matching a pattern |
cut -d',' -f2 | Extract a column from CSV |
sort | Sort file content |
uniq | Remove duplicate lines |
tr | Translate or delete characters |
sed – Stream Editor
1.Replace ERROR with ISSUE
Input (logfile.txt):
INFO: System boot ERROR: Disk full WARNING: Low memory ERROR: Network timeout
Command:
sed 's/ERROR/ISSUE/g' logfile.txt
Output:
INFO: System boot ISSUE: Disk full WARNING: Low memory ISSUE: Network timeout
This replaces all occurrences of ERROR with ISSUE without modifying the original file.
2. Remove WARNING lines
Input (logfile.txt):
INFO: System boot ERROR: Disk full WARNING: Low memory ERROR: Network timeout
Command:
sed '/WARNING/d' logfile.txt
Output:
INFO: System boot ERROR: Disk full ERROR: Network timeout
Deletes all lines containing the word WARNING.
awk – Pattern Scanning and Processing
1.Print first column
Input (data.csv):
id,name,score 1,Alice,85 2,Bob,92 3,Charlie,78
Command:
awk -F',' '{print $1}' data.csvOutput:
id 1 2 3
Prints the first column (IDs) from the CSV file.
2.Filter rows with score > 80
Input (data.csv):
id,name,score 1,Alice,85 2,Bob,92 3,Charlie,78
Command:
awk -F',' 'NR>1 && $3 > 80 {print}' data.csvOutput:
1,Alice,85 2,Bob,92
Skips the header and prints rows where the score column exceeds 80.
uniq – Remove Duplicate Lines
1. Remove adjacent duplicates
Input (names.txt):
Alice Bob Charlie Alice Bob
Command:
uniq names.txt
Output:
Alice Bob Charlie Alice Bob
Removes only consecutive duplicate lines.
2. Show only duplicates
Input (names.txt):
Alice Bob Charlie Alice Bob
Command:
sort names.txt | uniq -d
Output:
Alice Bob
Shows only names that appear more than once.
tr – Translate Characters
1.Convert lowercase to uppercase
Input (names.txt):
Alice Bob Charlie
Command:
tr 'a-z' 'A-Z' < names.txt
Output:
ALICE BOB CHARLIE
Converts all lowercase letters to uppercase.
Leave a Reply