Score:0

How can I pad numbers with leading zeroes using the seq command?

vn flag

I had to generate a text file for a given range of numbers. As usual I had to use seq range_start range_end > text_file.txt to put it in a text file.

I gave the seq range where the starting point was 01700 and the ending point was 01800. I know it's useless to have 0 before the number but in my case it was important. The file generated had lines like 1700, 1701 ... 1800. But there was no 0 before the numbers as I put in the command.

How am I supposed to put 0 before every line in the file? Or, is there any way to generate the text with 0 in it before every line?

Score:6
om flag

Try seq -w to keep consistent output width.

seq -w 01700 01800 will output 01700, 01701 etc.

As always, man seq should be your starting point when wondering about seq. Unix manpages are there for a reason, and very often solve such questions up front.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.