mirror of
https://github.com/jbranchaud/til
synced 2026-01-03 07:08:01 +00:00
Add Generate A Sequence Of Numbered Items as a Unix TIL
This commit is contained in:
@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
|
|||||||
|
|
||||||
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
|
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
|
||||||
|
|
||||||
_1694 TILs and counting..._
|
_1695 TILs and counting..._
|
||||||
|
|
||||||
See some of the other learning resources I work on:
|
See some of the other learning resources I work on:
|
||||||
|
|
||||||
@@ -1645,6 +1645,7 @@ If you've learned something here, support my efforts writing daily TILs by
|
|||||||
- [Fix Unlinked Node Binaries With asdf](unix/fix-unlinked-node-binaries-with-asdf.md)
|
- [Fix Unlinked Node Binaries With asdf](unix/fix-unlinked-node-binaries-with-asdf.md)
|
||||||
- [Forward Multiple Ports Over SSH](unix/forward-multiple-ports-over-ssh.md)
|
- [Forward Multiple Ports Over SSH](unix/forward-multiple-ports-over-ssh.md)
|
||||||
- [Generate A SAML Key And Certificate Pair](unix/generate-a-saml-key-and-certificate-pair.md)
|
- [Generate A SAML Key And Certificate Pair](unix/generate-a-saml-key-and-certificate-pair.md)
|
||||||
|
- [Generate A Sequence Of Numbered Items](unix/generate-a-sequence-of-numbered-items.md)
|
||||||
- [Generate Base64 Encoding Without Newlines](unix/generate-base64-encoding-without-newlines.md)
|
- [Generate Base64 Encoding Without Newlines](unix/generate-base64-encoding-without-newlines.md)
|
||||||
- [Generate Random 20-Character Hex String](unix/generate-random-20-character-hex-string.md)
|
- [Generate Random 20-Character Hex String](unix/generate-random-20-character-hex-string.md)
|
||||||
- [Get A List Of Locales On Your System](unix/get-a-list-of-locales-on-your-system.md)
|
- [Get A List Of Locales On Your System](unix/get-a-list-of-locales-on-your-system.md)
|
||||||
|
|||||||
39
unix/generate-a-sequence-of-numbered-items.md
Normal file
39
unix/generate-a-sequence-of-numbered-items.md
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
# Generate A Sequence Of Numbered Items
|
||||||
|
|
||||||
|
The `seq` command will output the specified sequence of numbers.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
❯ seq 1 5
|
||||||
|
1
|
||||||
|
2
|
||||||
|
3
|
||||||
|
4
|
||||||
|
5
|
||||||
|
```
|
||||||
|
|
||||||
|
With the `-f` (`--format`) flag we can interpolate those numbers as part of a
|
||||||
|
string.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
❯ seq -f "day_%02g" 1 5
|
||||||
|
day_01
|
||||||
|
day_02
|
||||||
|
day_03
|
||||||
|
day_04
|
||||||
|
day_05
|
||||||
|
```
|
||||||
|
|
||||||
|
The `%g` indicates that there is a format specifier for a numeric type which is
|
||||||
|
where `seq` will inject the current value in the sequence. The `02` indicates
|
||||||
|
that it should be `0` padded to `2` digits.
|
||||||
|
|
||||||
|
We can then pipe this to another unix command, such as `mkdir` in order to
|
||||||
|
quickly create a bunch of directories for, say, [Advent of Code](https://adventofcode.com/2024).
|
||||||
|
|
||||||
|
```bash
|
||||||
|
❯ mkdir aoc_2024
|
||||||
|
❯ cd aoc_2024
|
||||||
|
❯ seq -f "day_%02g" 1 25 | xargs mkdir
|
||||||
|
```
|
||||||
|
|
||||||
|
See `man seq` for more details.
|
||||||
Reference in New Issue
Block a user