KandZ – Tuts

We like to help…!

Linux CLI 49 🐧 pr and printf commands

a - pr command
pr command is used to paginate or columnate file/files
common options: -m → prints files side by side
-l #number → page length in lines
-#number → specifies the number of columns
-h header → specifies the header as the header of the output
pr -m -l 10 file1.txt file2.txt → prints the files side by sile, 10 lines length
pr -3 -l 10 file1.txt → prints the file in 3 columns and 10 lines length

b - printf command
printf command is used to format and print data on the screen.
It can be used to display strings, integers, sfloating-point number and characters
common specifiers: %s → prints a string
%d → prints a decimal number %f → prints a floating-point number
%x → prints a hexadecimal number %o → prints an octal number
%c → prints a single character %e → prints a scientific notation
printf "My favorite number is %d and my favorite letter is %c.\n" 42 'A'→ replaces %d with 42 and %c with A
printf "Pi is approximately %.2f\n" 3.14159→ replaces the specifier with 3.14, it has two decimals
printf "%b\n" "Hello, World! \n" "How are you doing\n"→ prints the text and handles \n as new line

Leave a Reply