Linux Text Processing
Text manipulation commands
Display Text
echo text # print text
cat file # display file
cat file1 file2 > file3 # concatenate files
Sort and Unique
sort file # sort lines
sort -r file # reverse sort
sort -n file # numeric sort
uniq file # remove duplicate lines
sort file | uniq # sort and remove duplicates
Word Count
wc file # lines, words, bytes
wc -l file # count lines
wc -w file # count words
wc -c file # count bytes
Cut and Paste
cut -d: -f1 file # extract field 1 (delimiter :)
cut -c1-10 file # extract characters 1-10
Stream Editor (sed)
sed s/old/new/ file # replace first occurrence
sed s/old/new/g file # replace all occurrences
sed -i s/old/new/g file # edit file in-place
sed 1,5d file # delete lines 1-5
AWK
awk {print $1} file # print first column
awk -F: {print $1} file # custom delimiter
awk {sum+=$1} END {print sum} # sum first column