Skip to main content

echo, printf, tr, wc


echo

Built-in Linux feature to print out arguments as standard output.

echo {string}

printf

Similar to echo, but allows for more control over the formatting of output.

printf {string}
Option Function
\n newline
printf "hello \n how are you"


tr

tr performs operations like removing repeated characters, converting uppercase to lowercase, and basic character removal

 or replacement.

tr {character 1} {character 2}
echo 'linuxize' | tr 'lin' 'red'
reduxeze

In this example, tr has been used to replace the occurrence of 'lin' with 'red'.


wc

wc, or wordcount, is a function used for counting a part of an output. wc can be used to count the number of words, lines, characters, or bytes in a file or output.

wc [options] {filename}
Option Function
-l Line count
-c byte count
-m

character count

-w

word count


sort

Linux utility for sorting lines of text files.

sort [options] {filename}
Option Function
-k {column number) Sort by values in a specified column.
-n Sorts based on numerical value
-r Sorts fields in descending order
-t Seperate one field from another

cut

Extracts specified lines of text from a file.

cut [options] {filename}
Option Function
-c Specify the number of characters to cut from each line.
-d {delimter} Seperate one field from another.
-f {fieldnumber) Specify the field numbers to cut as separated by the delimiter. IE f2 would be the field between the first and second instances of the delimiter.
-s Suppress a line if a delimiter is not found.

paste

Used to merge lines from text files horizontally.


diff

Used to compare text files.

diff [options] {file1} {file2}
Option Function
-b

Ignore spacing differences

-i  ignore case differences
-t Expand tab characters in output lines
-w  Ignore spacing differences and tabs
-c  Display a list of differences with three lines of context
-u Output results in unified mode.