The Linux seq command can generate lists of numbers at lightning speed, and it's also easy to use and flexible. One of the easiest ways to generate a list of numbers in Linux is to use the seq (sequence) command. In its simplest form, seq takes a number as an argument and outputs a list from 1 to that number. For example:
Unless otherwise specified, seq always starts with 1. You can start a sequence by inserting a different number before the final number.
Specify Increment You can also specify the increment step. Suppose you want to list the multiples of 3. Specify the starting point (the first 3 in this example), the increment (the second 3), and the end point (18).
You can choose to use negative increments (i.e. decrements) to go from larger to smaller numbers.
The seq command is also very fast. You could probably generate a list of a million numbers in 10 seconds. $ time seq 1000000 1 2 3 … … 999998 999999 1000000 real 0m9.290s <== 9+ seconds user 0m0.020s sys 0m0.899s Using Delimiters Another very useful option is to use a separator. Instead of listing a single number on each line, you can insert a comma, colon, or some other character. The -s option is followed by the character to be used.
In fact, if you just want the numbers to fit on one line, you can use spaces instead of the default line breaks.
Start math It may seem like a big leap to go from generating sequences of numbers to doing math with them, but with the right delimiter, seq can easily be passed to bc for calculations. For example:
What happened in this command? let's see. First, seq generates a list of numbers using * as the delimiter.
It then passes the string to a calculator (bc), which immediately multiplies the numbers. You can do pretty massive calculations in less than a second. $ time seq -s* 117 | bc 39699371608087208954019596294986306477904063601683223011297484643104\ 22041758630649341780708631240196854767624444057168110272995649603642\ 560353748940315749184568295424000000000000000000000000000 real 0m0.003s user 0m0.004s sys 0m0.000s limitation You can only choose one delimiter, so the calculations will be very limited. Using bc alone can perform more complex mathematical operations. Also, seq only works with numbers. To generate a sequence of single letters, use the following command instead:
Summarize The above is what I introduced to you about using the Linux seq command to generate digital sequences. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website! You may also be interested in:
|
<<: Mini Programs use Mini Program Cloud to implement WeChat payment functions
>>: A Brief Analysis of the Differences between “:=” and “=” in MySQL
Table of contents Project Background Improvement ...
1. Uninstalling MySQL 5.7 1.1查看yum是否安裝過mysql cd y...
GitHub address, you can star it if you like it Pl...
Application example website http://www.uhuigou.net...
You can use the command: docker tag [image id] [n...
Following the previous article 202 Free High-Qual...
background An nginx server module needs to proxy ...
MySQL 5.7.9 version sql_mode=only_full_group_by i...
Table of contents 1. Listening for events 2. Pass...
In the past few days, I have studied how to run s...
NodeJS copies the files: Generally, the copy oper...
This article mainly introduces how to call desktop...
The following error occurred while installing the...
1. Image formats supported on the WEB: GIF: can s...
In actual Web development, inserting images, incl...