Need to process text files quickly and efficiently? In this video, we’ll show you how to use sed and awk for common text manipulation tasks. From replacing text to calculating averages, these powerful tools are essential for any Linux user. Let’s dive into a simple guide with practical examples!
Learn:
✅ Step-by-Step Guide:
Create Test Files:
Create pets.txt:
echo -e "cat and other cat\ndog \ncat food" 〉 pets.txt
Create grades.txt:
echo -e "Alex 85\nAkira 72\nZara 90" 〉 grades.txt
Commands to Try:
Replace First Match Text Per Line (sed):
sed 's/cat/dog/' pets.txt
What it does: Changes the first "cat" to "dog" for each line.
Example output: "dog and other cat", "dog", "dog food"
Note: Use -i option to overwrite the original file.
Replace All Matches Text (sed):
sed 's/cat/dog/g' pets.txt
What it does: Replaces all occurrences of "cat" with "dog".
Get 1st Column (awk):
awk '{print $1}' grades.txt
What it does: Shows only the first column (names).
Example output: "Alex", "Akira", "Zara"
Calculate Average (awk):
awk '{sum+=$2} END {print sum/NR}' grades.txt
What it does: Averages the numbers in the second column.
Example output: 82.3333
Filter Lines (awk):
awk '$2 〉= 80' grades.txt
What it does: Shows lines where the grade is 80 or higher.
Example output: "Alex 85", "Zara 90"
✅ Quick Cheat Sheet:
Change text: sed 's/old/new/' file
Delete lines: sed '/word/d' file
Show column: awk '{print $N}' file
Sum numbers: awk '{sum+=$N} END{print sum}' file
Filter rows: awk '$N 〉 value' file
✅ Pro Tips:
Edit files directly: Use sed -i 's/old/new/' file to modify files in place.
Count lines: Use awk 'END{print NR}' file to count the number of lines.
Combine commands: Chain sed and awk for more complex processing.
Example: sed 's/cat/dog/' pets.txt | awk '{print $1}'
You can find this guide md and pdf files at this GitLab link: https://gitlab.com/hatem-badawi/linux....
Hit subscribe for more Linux tips and like if this helped.
Let us know: What text processing task will you tackle first?
👉 Watch now and master sed and awk for efficient text processing!
#LinuxTips #TextProcessing #SedAwk #CommandLine #ProductivityHacks
(Short, clear, and packed with practical knowledge!)
En esta página del sitio puede ver el video en línea Simple sed & awk Guide – Master Text Processing in Linux! de Duración hora minuto segunda en buena calidad , que subió el usuario LinuxHowTo 05 agosto 2025, comparta el enlace con amigos y conocidos, en youtube este video ya ha sido visto 37 veces y le gustó 0 a los espectadores. Disfruta viendo!