Selected topic
Text Processing
Prefer practical output? Use related tools below while reading.
cat (Concatenate)cat filename.txthead and tailhead: displays the first 10 lines by default, but can be customized with -n option (e.g., head -5 filename.txt)
+ tail: displays the last 10 lines by default, but can be customized with -n option (e.g., tail -3 filename.txt)
sed (Stream Editor)sed 's/old_text/new_text/g' filename.txt (replaces "old_text" with "new_text")grep (Global Regular Expression Print)grep keyword filename.txtcutcut -d ',' -f 1 filename.csv (extracts first field using comma as delimiter)sort and uniqsort: sorts in ascending order by default; use -r option for descending order (e.g., sort -r filename.txt)
+ uniq: removes duplicate lines from a sorted file
awkawk '{print $1}' filename.txt (prints the first field of each line)Example Use Case: Suppose you have a file named students.csv with the following contents:
John,20,Male
Jane,21,Female
Bob,19,Male
Alice,22,Femalehead -3 students.csvsed 's/Male/Boy/g' students.csvsort -r -k 2 students.csv