Seq command usage in linux

Source: Internet
Author: User
Example 1: # seq110 returns 12345678910 Example 2 :#! /Bin/bashforiin 'seq110 '; doecho $ I; done or foriin $ (seq110) can also be seq-f ,... used to generate all integers between one number and the other.
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)
Yes.
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
% The default number of digits after the specified number is "% g ",
"% 3g", less than a digit is a space
# Sed-f "% 03g" 9 11. if this is the case, less than 0 digits are allowed.
% String
Seq-f "str % 03g" 9 11
Str009
Str010
Str011
-W indicates that the output number is the same as the width and cannot be used together 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 of the same width.
-S: the default delimiter is carriage return.
Seq-s ""-f "str % 03g" 9 11
Str009 str010 str011
You must specify \ t as the separator.
Seq-s "'echo-e" \ t "'" 9 11
Specify \ n as the separator
Seq-s "'echo-e" \ n "'" 9 11
19293949596979899910911
An error is returned.
However, this is not necessary. the default carriage return is used as the separator.
 
Examples
 
Awk 'In in {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/polici.jpg#/img]; then
Wget-P $ HOME/tmp-c $ _
Fi
Done
 
 
Seq in Linux ???? Is generally used as a bunch? What is the base value? ?? Method, such
Seq 1 10
Then ?? Effecf
1
2
3
4
5
6
7
8
9
10
It? There are three ????
-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 the most commonly used, for example, making 10 ?? Dir001, dir002... dir010 ?, It is very useful, I ?? Yes
?? Chaos ?? The command is ready.
Seq-f'dir % 03g '1 10 | xargs mkdir
Or
Mkdir $ (seq-f'dir % 03g '1 10)
It uses the printf format, and % 03g represents a three-digit floating ??? In this way, for example, the bash3 printf
Or? Why? R command
Printf 'dir % 03d \ n' {1 .. 10} | xargs mkdir or mkdir 'printf' dir % 03d '{1 .. 10 }'
Awk? You can also
Awk 'In in {while (num <10) printf "dir % 03d \ n", ++ num; exit} '| xargs mkdir
?????? 1 ??? Fast, no ?? Cheng
For dir in 001 002 003 004 005 006 007 008 009 010
Do
Mkdir dir $ {dir}
Done
I also use seq? Use? Base value? Peg, as long as there is a format? Pig? Order is available, especially for some xxx sites
For I in 'seq-f' % 02g'1 20'
Do
If! Wget-P $ HOME/tmp-c [img] http://www.xxxsite.com/photo/polici.jpg#/img]; then
Wget-P $ HOME/tmp-c $ _
Fi
Done
 
-S ?? Major changes ?? Out of the Shard ,?? Yes \ n, that is, newline
Can I change it with-s ?, For example
Seq-s ''1 10
1 2 3 4 5 6 7 8 9 10, with spaces? Cool finger? However, in Gnu seq, it seems that
\ N, \ t... and other characters are not supported? For example, use \ n ??? Space ?? Cheng
[Victor @ localhost ~] $ Seq-s'
>
> '1 5
1
 
2
 
3
 
4
 
5
\ T to change? IFS, for example, \ t
OIFS = $ IFS
IFS = "\ t"
Seq-s 'echo-e $ IFS '1 5
IFS = $ OIFS
Are other characters ?? Why? Br/>
 
The seq command is used to print a string of ordered numbers. it consists of the following three parameters:
 
-F, -- format = FORMAT
Use printf style floating-point FORMAT (default: % g)
-F: specifies the print format:
For example:
[Root @ hao32] # seq-f % 05g 2 7
00002
00003
00004
00005
00006
00007
 
-S, -- separator = STRING
Use STRING to separate numbers (default: \ n)
-S: the default delimiter is carriage return:
For example:
[Root @ hao32] # seq-s "" 2 7
2 3 4 5 6 7
 
-W, -- equal-width
Equalize width by padding with leading zeroes
-W outputs are supplemented with "0" when the front of the same width is insufficient, that is, they are aligned with the maximum number of digits.
For example:
[Root @ hao32] # seq-w 2 11
02
03
04
05
06
07
08
09
10
11

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.