Results 1 to 5 of 5

Thread: Printing Sequence of Character with Single Space

  1. #1
    Join Date
    Nov 2009
    Location
    Chennai India
    Beans
    350

    Printing Sequence of Character with Single Space

    How to print a sequence of characters with single space or tabs when the printf command is used in this way ?

    Code:
    #!/bin/bash
    for ((x=1;x<=1391;x+=1)); 
    do
    echo `printf "%08d" $x`.pdf ;
    done
    I want the bash to print the output like this

    Code:
    00000001.pdf 00000002.pdf 00000003.pdf  .......

  2. #2
    Join Date
    Apr 2012
    Beans
    7,256

    Re: Printing Sequence of Character with Single Space

    I don't think you need the 'echo' in there, that will always add the newline - and your format specifier needs to be a string not an integer (you are printing the whole name, not just the $x) - after that, you can just use a literal space as the separator

    Code:
    $ for ((x=1;x<=1391;x+=1));  do printf "%08s " $x.pdf ; done
    However the built-in sequence syntax would be neater imho:

    Code:
    $ for f in {00000000..00001391}.pdf; do printf "$f "; done

  3. #3
    Join Date
    Jul 2007
    Location
    Poland
    Beans
    4,499
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Printing Sequence of Character with Single Space

    Code:
    echo {0000000..00001391}.pdf
    what do you need it for?
    if your question is answered, mark the thread as [SOLVED]. Thx.
    To post code or command output, use [code] tags.
    Check your bash script here // BashFAQ // BashPitfalls

  4. #4
    Join Date
    Nov 2009
    Location
    Chennai India
    Beans
    350

    Re: Printing Sequence of Character with Single Space

    Quote Originally Posted by steeldriver View Post
    I don't think you need the 'echo' in there, that will always add the newline - and your format specifier needs to be a string not an integer (you are printing the whole name, not just the $x) - after that, you can just use a literal space as the separator

    Code:
    $ for ((x=1;x<=1391;x+=1));  do printf "%08s " $x.pdf ; done
    However the built-in sequence syntax would be neater imho:

    Code:
    $ for f in {00000000..00001391}.pdf; do printf "$f "; done
    Thank you SO Much, that solves the problem.

  5. #5
    Join Date
    Nov 2009
    Location
    Chennai India
    Beans
    350

    Re: Printing Sequence of Character with Single Space

    Quote Originally Posted by Vaphell View Post
    Code:
    echo {0000000..00001391}.pdf
    what do you need it for?
    For combing a Chinese Hakka to English Dictionary which I downloaded from the internet. The Dictionary has around 1391 pages. Unfortunately . I got 1391 pdf files. So I wanted to combine it.

    Anyways, you idea too worked , Thank you so much.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •