How can I print a range of ip addresses on linux command line using the "seq" command? For eg: I need seq to print a range of ip from to . Seems like the period in between the octets causes the number to behave like a floating point . I am getting a "invalid floating point argument error" . I tried using the -f option . May be I am not using it correctly. But it still gave me an error. I am trying to something similar to


Is there another way to print IP addresses in a range in Linux other than switching over to excel ?

  • 5
    With bash, that range of addresses can be printed with echo 10.0.0.{2..23}. The {..} construct is called brace expansion.
    – John1024
    Nov 20, 2014 at 7:02

6 Answers 6


Use a format:

$ seq -f "10.20.30.%g" 40 50

Unfortunately this is non-obvious as GNU doesn't like to write man pages.

  • 2
    I think it would be better to reference the manual they do provide than only noting that the man page specifically is overly brief. See info coreutils 'seq invocation'. Nov 20, 2014 at 7:23
  • 1
    @HåkanLindqvist I hate, absolutely hate, GNU info. And not to mention that %g isn't documented there, either; you have to hunt down the right printf info page. Nov 20, 2014 at 7:31
  • 2
    Absolutely, referencing man 3 printf as well is a good idea in case the reader is not familiar with printf format strings. That said, I'm not a big fan of their use of texinfo either but this was just my suggestion for improving your answer by making use of the documentation that does exist over just pointing out the lacking documentation in a specific format. Nov 20, 2014 at 7:59

There is the prips utility which generates an IP list from a range or CIDR. Useful for work with large ranges:

$ prips

$ prips

You can use sed command with seq to print range of IP address.

seq 2 23 | sed 's/^/10.0.0./'

OR using echo and tr

echo 10.0.0.{2..23} | tr ' ' '\n'

The printf command performs implicit iteration if it is given more arguments than conversion specifiers. For example:

$ printf "%s-%s\n" 1 2 3 4 5 6

There are two conversions, but six arguments. So three repetitions of the formatting logic occur, marching over the arguments pairwise.

With that we can do:

printf "10.0.0.%s\n" $(seq 1 23)

The printf command, and its repeating behavior, are POSIX standard: "The format operand shall be reused as often as necessary to satisfy the argument operands." On the other hand, the seq command isn't.

for i in $(seq 2 23); do echo "10.0.0.$i"; done
  • @don_crissti, why?
    – user163009
    Mar 27, 2016 at 14:53
  • "Why" wha​​​​t​​​​​​ ​ ? Mar 27, 2016 at 15:15
  • the edit and downvote?
    – user163009
    Mar 27, 2016 at 15:17
  • I'm not the downvoter - most likely the system automatically downvoted your answer. I only reviewed it (edited it). As to why edit ? Well, because it's code and should be properly formatted. Mar 27, 2016 at 15:19

If we remove the requirement to use the seq command, and assume that the ipcalc command is available, and the Ubuntu prips command is not, then prips can be implemented as a Bash shell function:

prips() {

  # range is bounded by network (-n) & broadcast (-b) addresses.
  lo=$(ipcalc -n $cidr |cut -f2 -d=)
  hi=$(ipcalc -b $cidr |cut -f2 -d=)

  read a b c d <<< $(echo $lo |tr . ' ')
  read e f g h <<< $(echo $hi |tr . ' ')

  eval "echo {$a..$e}.{$b..$f}.{$c..$g}.{$d..$h}"

Note that this will include the network address and broadcast address in the range; if that is a problem, delete the first and last address from the result.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.