Use of the SEQ command

Source: Internet
Author: User
Tags mkdir
Used to produce all integers from one number to another
Example one:
# seq 1 10
The result is 1 2 3 4 5 6 7 8 9 10
Case TWO:
#!/bin/bash
For i in ' seq 1 10 ';
Todo
echo $i;
Done
or use
For I in $ (SEQ 1 10)
can also be 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 options specified format
#seq-F "%3g" 9 11
9
10
11
% the number of digits specified after the default is "%g",
"%3G" so the number of digits is not enough space
#sed-F "%03g" 9 11 so the number of digits is less than 0.
% before making strings
Seq-f "STR%03G" 9 11
str009
str010
STR011-W specifies that the output number is the same width cannot be used with-f
Seq-w-F "str%03g" 9 11
Seq:format string May is specified when printing equal width strings
SEQ-W 98 101
098
099
100
101
The output is the same width-s-specified delimiter is carriage return by default
Seq-s ""-F "str%03g" 9 11
str009 str010 str011
To specify/t as the separator symbol
Seq-s "' Echo-e"/t "'" 9 11 specifies/n/n as separator symbol
Seq-s "' Echo-e"/n/n "'" 9 11
19293949596979899910911
Got a wrong result.
But generally there is no need for it the default is to enter as a separator for several examples

awk ' BEGIN {while (num <) printf "dir%03d/n", ++num exit} ' | Xargs mkdir
mkdir $ (seq-f ' dir%03g ' 1 10)

For i in ' seq-f '%02g ' 1 20 '
Todo
if! Wget-p $HOME/tmp-c [img]http://www.xxxsite.com/photo/$i. jpg[/img]; Then
Wget-p $HOME/tmp-c $_
Fi
Done

SEQ is a preset external command in Linux that is used as a simple method of writing a bunch of numbers, such as
Seq 1 10
will appear
1
2
3
4
5
6
7
8
9
10
And it has three options.
-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 is most commonly used, such as one-time system to make 10 famous dir001, dir002. DIR010 's catalogue, it is very useful, we can
So the next command is available.
Seq-f ' dir%03g ' 1 10 | Xargs mkdir
Or
mkdir $ (seq-f ' dir%03g ' 1 10)
It's in printf format,%03g ' represents a three-bit floating point, in this way, as with BASH3 printf
can also serve as a price order.
printf ' dir%03d/n ' {1..10} | Xargs mkdir or mkdir ' printf ' dir%03d ' {1..10} '
Awk can, of course,
awk ' BEGIN {while (num <) printf "dir%03d/n", ++num exit} ' | Xargs mkdir
It's faster than writing a foot, and you don't have to write
For DIR in 001 002 003 004 005 006 007 008 009 010
Todo
mkdir Dir${dir}
Done
I also used to download some of the use of seq jpeg, as long as the format has a number of words can be, especially in some XXX site;)
For i in ' seq-f '%02g ' 1 20 '
Todo
if! Wget-p $HOME/tmp-c [img]http://www.xxxsite.com/photo/$i. jpg[/img]; Then
Wget-p $HOME/tmp-c $_
Fi
Done

The-s option is mainly to change the output of the separator, the preset is/n, is newline
If you use-s to change, such as
Seq-s ' 1 10
1 2 3 4 5 6 7 8 9 10, with a space as the cell, but in the Gnu seq, it seems
Do not support/n,/t ... and other characters. If you use/n/n, with two spaces, you have to write
[Victor@localhost ~]$ seq-s '
>
> ' 1 5
1

2

3

4

5
/t will have to change the IFS, such as using/t/t
oifs= $IFS
Ifs= "/t/t"
Seq-s ' Echo-e $IFS ' 1 5
ifs= $OIFS
So is the other character.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.