-1

Looking for a UNIX command to execute it from application.

How to prefix zero's to make the total number as 8 digits for a word count of a specific file and print the output to a file, ex:

$ wc -l < test  if the output is 200  

I need to change it to 00000200 and it should go into a file. Word count may change for each file because of it the command should be generic.

James Brown
  • 36,089
  • 7
  • 43
  • 59
  • There seems to be some examples of how to do it: https://stackoverflow.com/questions/8789729/how-to-zero-pad-a-sequence-of-integers-in-bash-so-that-all-have-the-same-width – James Brown May 09 '19 at 15:41

2 Answers2

0

You could use awk and printf, for example:

wc -l test.file | awk '{printf "%08d\n", $1}'
nbari
  • 25,603
  • 10
  • 76
  • 131
  • this one is working perfect, just add one extension to my question the output of this command, should replace footer of "testfile2.txt" can you frame the command for this one please – user11476256 May 09 '19 at 16:14
0

Using Bash's printf:

$ printf "%08d\n" $(wc -l < file)
00000200
James Brown
  • 36,089
  • 7
  • 43
  • 59