Seq command usage in linux

Source: Internet
Author: User
Tags print format

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 is an external command set by a Linux operating system. It is generally used as a batch of data, such
Seq 1 10
Then
1
2
3
4
5
6
7
8
9
10
It also 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. For example, it is useful to create ten dir001, dir002... dir010 targets at a time. We can
In this case, the next command is ready.
Seq-f'dir % 03g '1 10 | xargs mkdir
Or
Mkdir $ (seq-f'dir % 03g '1 10)
It uses the printf format. % 03g represents three floating points. This method is used, for example, the printf of bash3.
It can also be used as a waiting command
Printf 'dir % 03d \ n' {1 .. 10} | xargs mkdir or mkdir 'printf' dir % 03d '{1 .. 10 }'
Awk certainly does.
Awk 'in in {while (num <10) printf "dir % 03d \ n", ++ num; exit} '| xargs mkdir
This is faster than creating a notebook, so you don't have to convert it
For dir in 001 002 003 004 005 006 007 008 009 010
Do
Mkdir dir $ {dir}
Done
I also use digital jpeg in seq, as long as the format has a sequential order of numbers, 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
 
The-s option mainly changes the shard output. The Delimiter is \ n, Which is newline.
-S can be used for change, as shown in figure
Seq-s ''1 10
1 2 3 4 5 6 7 8 9 10, with space as the shard, but in the Gnu seq, it seems
\ N, \ t... and other characters are not supported? For example, use \ n and use two spaces to convert them
[Victor @ localhost ~] $ Seq-S'
>
> '1 5
1
 
2
 
3
 
4
 
5
\ T, you need to change IFS, for example, \ t
OIFS = $ IFS
IFS = "\ t"
Seq-s 'echo-e $ IFS '1 5
IFS = $ OIFS
Is the same for other characters?
 
 
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.