printf on sh or bash shell
The content of test.txt are as follows:
Name Chinese English Math Average
DmTsai 80 60 92 77.33
VBird 75 55 80 70.00
Ken 60 90 70 73.33
Example 1:
The content of the file test.txt with data just above only lists names and grades: (separated by [tab])
printf '%s\t %s\t %s\t %s\t %s\t \n' $(cat test.txt)
Example 2:
After the second line in test.txt display as string, integer and decimal point respectively:
printf '%10s %5i %5i %5i %8.2f \n' $(cat test.txt | grep -v Name)
- %10s : Represents a string field with a length of 10 characters.
- %5i : Represents a numeric field with a length of 5 characters.
- %8.2f : Represents a field with a decimal point with a length of 8 characters, where the decimal point has a width of 2 characters, the decimal point itself (.) occupies one place
Example 3:
List the characters represented by the hexadecimal value 45?
printf '\x45\n'
Comments
Post a Comment