Text tools: grep, sort, uniq, wc, cut, tr
Sign in to read this lesson
Logs and configuration files are text, so an admin filters text every day. In this lesson we learn to find the lines we need (grep), sort and count repeats (sort, uniq), count lines and words (wc), cut columns (cut) and replace characters (tr).
What you will learn
grep word fileshows lines containing the word:-iignore case,-vthe lines without it,-nwith line numbers,-rin a directory,-cthe count.sortsorts lines (-nas numbers,-rreversed);uniqmerges adjacent repeats,uniq -ccounts them.- The classic chain:
sort | uniq -c | sort -rn— the most repeated items on top. wc -lcounts lines;cut -d: -f1cuts a column by a delimiter.trreplaces or deletes characters:tr a-z A-Zconverts to upper case.
The lesson has 5 key points, an explanation and 5 questions. It opens with a package.