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.txtSorts lines alphabetically or numerically with customizable keys and delimiters.
sort -nrk 5 file.txtRemoves consecutive duplicate lines from sorted input.
sort file.txt | uniq -cExtracts specific fields or character positions from each line.
cut -d ':' -f 1 /etc/passwdCombines multiple files line-by-line horizontally.
paste file1.txt file2.txtPerforms database-style joins on files with shared key fields.
join names.txt grades.txtCompares two sorted files and outputs differences and matches.
comm -12 sorted1.txt sorted2.txtDisplays changes between two text files in various formats.
diff -u old.txt new.txtApplies differences produced by diff to update files efficiently.
patch < changes.diffTranslates or deletes characters from input streams.
echo "hello" | tr a-z A-ZPerforms advanced stream editing like substitution, filtering, and transformation.
sed 's/foo/bar/' input.txtChecks and corrects spelling errors interactively or in batch mode.
aspell check document.txtLinux 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.