Usage of seq command in linux

Used to generate all integers from a certain number to another number.
Example 1:
# seq 1 10.
The result is 1 2 3 4 5 6 7 8 9 10.
Example 2:
#!/bin/bash
for i in `seq 1 10`;
do
echo $i;
done
or use
for i in $(seq 1 10)
or
seq
-f, --format=FORMAT use printf style floating-point FORMAT (default: %g)
-s, --separator =STRING use STRING to separate numbers (default: \n)
-w, --equal-width equalize width by padding with leading zeroes
-f option specifies the format
#seq -f"%3g" 9 11
9
10
11
% specifies the number after The default number of digits is "%g", 
"%3g", then the insufficient number of digits is a space.
#sed -f "%03g" 9 11 In this case, the insufficient number of digits is 0
%. Specify the string before
seq -f "str%03g" 9 11
str009
str010
str011
-w specifies that the output numbers are of the same width. It cannot be used with -f.
seq -w -f "str%03g" 9 11
seq: format string may not be specified when printing equal width. strings
seq -w 98 101
098
099
100
101
The output is the same width
-s specifies the delimiter. The default is carriage return
seq -s" " -f"str%03g" 9 11
str009 str010 str011
needs to specify \t as the delimiter
seq -s"`echo -e "\t"`" 9 11
Specify \n\n as the delimiter
seq -s"`echo -e "\n\n"`" 9 11
19293949596979899910911
The result obtained is an error
, but it is generally There is no need for it. The default is carriage return as the separator.
 
A few examples
 
: awk 'BEGIN { while (num < 10) printf "dir%03d\n",++num ; exit}' | xargs mkdir
mkdir $(seq -f 'dir%03g' 1 10)
 
for i in `seq -f '%02g' 1 20`
do
if ! wget -P $HOME/tmp -c [img]http://www.xxxsite.com/photo/$i.jpg[/img] ; then
wget -P $HOME/tmp -c $_
fi
done
 

Guess you like

Origin blog.csdn.net/liuwkk/article/details/108796019
Recommended