Linux systems treat text files as primary sources for configuration, code, documentation, and data exchange. Knowing how to manipulate and transform text is essential for effective Linux usage. This article covers command-line tools for filtering, formatting, comparing, and correcting text data.
Concatenates and displays files. Useful for combining, numbering, or visualizing content.
cat -ns file.txt
Sorts lines alphabetically or numerically with customizable keys and delimiters.
sort -nrk 5 file.txt
Removes consecutive duplicate lines from sorted input.
sort file.txt | uniq -c
Extracts specific fields or character positions from each line.
cut -d ':' -f 1 /etc/passwd
Combines multiple files line-by-line horizontally.
paste file1.txt file2.txt
Performs database-style joins on files with shared key fields.
join names.txt grades.txt
Compares two sorted files and outputs differences and matches.
comm -12 sorted1.txt sorted2.txt
Displays changes between two text files in various formats.
diff -u old.txt new.txt
Applies differences produced by diff
to update files efficiently.
patch < changes.diff
Translates or deletes characters from input streams.
echo "hello" | tr a-z A-Z
Performs advanced stream editing like substitution, filtering, and transformation.
sed 's/foo/bar/' input.txt
Checks and corrects spelling errors interactively or in batch mode.
aspell check document.txt
Linux text-processing utilities provide unparalleled control over data manipulation. Whether you're analyzing logs, cleaning datasets, or automating reports, tools like sed
, diff
, and aspell
offer precision and efficiency. By mastering these commands, users unlock the full potential of the Linux shell and streamline daily workflows.