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

Popular posts from this blog

BdsDex: failed to load Boot0001 "UEFI BHYVE SATA DISK BHYVE-OABE-20A5-E582" from PciRoot(0x0)/Pci (0x2, 0x0)/Stat(0x0,0xFFFF,0x0) : Not Found

How To Install Nginx, MySQL and PHP (FEMP) Stack on FreeBSD 13.0

Install samba on FreeBSD(on VMware Workstation) to share files with Window.