forked from ayoisaiah/f2
-
Notifications
You must be signed in to change notification settings - Fork 0
Indexing
Ayooluwa edited this page May 29, 2021
·
7 revisions
F2 supports indexing using an auto incrementing number. This makes it easy to product output such as "01 - ABC.mp3", "02 - XYZ.mp3", "03 - 123.mp3", or "log001.txt", "log002.txt", e.t.c. The indexing format can be as simple or as complex as you like. It supports several optional configurations such as step, padding with zeros, numbers to skip, and where the index should begin. The complete syntax is <start>%<padding>d<format><step><skip>
.
Here are some forms of indexing that can be used:
-
%d
: The most basic way to index with yields: 1, 2, 3, 4, e.t.c. -
5%d
:5
is the start number so this yields: 5, 6, 7, 8, e.t.c. -
5%02d
:02
here is the minimum width of the number. The number will be padded with zeros to reach this width so: 05, 06, 07, 08, e.t.c. Note that padding does not affect other number systems such as Roman numerals, octal, binary and hexadecimal formats. -
%02dr
:r
signifies Roman numerals so we get: "I", "II", "III", "IV", e.t.c. This works well up to 3999 (MMMCMXCIX). From 4000 and above, the number will be in decimal format. -
%db
:b
signifies binary format: 1, 10, 11, 100, e.t.c. Similarly, theh
in%dh
signifies hexadecimal formal and theo
in%do
signifies octal format. -
10%03d5
: The5
here signifies the step used to increment the numbers so this yields: 010, 015, 020, 025, e.t.c. -
%d<1-5,7-8,11>
: The numbers between the angle brackets signify what numbers are to be skipped during the indexing. This yields: 6, 9, 10, 12, e.t.c.
Important note for Windows users: Always use double quotes when passing arguments to any flag in the Command Prompt (CMD). Powershell users may use single or double quotes.
$ f2 -f '.*' -r '%03d_{{f}}{{ext}}'
+----------------------------------+--------------------------------------+--------+
| INPUT | OUTPUT | STATUS |
+----------------------------------+--------------------------------------+--------+
| alternatives.log | 001_alternatives.log | ok |
| auth.log | 002_auth.log | ok |
| dpkg.log | 003_dpkg.log | ok |
| error.log | 004_error.log | ok |
| fontconfig.log | 005_fontconfig.log | ok |
| history.log | 006_history.log | ok |
| kern.log | 007_kern.log | ok |
| mongod.log | 008_mongod.log | ok |
| postgresql-12-main.log | 009_postgresql-12-main.log | ok |
| sysinfo.log | 010_sysinfo.log | ok |
| term.log | 011_term.log | ok |
| unattended-upgrades-shutdown.log | 012_unattended-upgrades-shutdown.log | ok |
+----------------------------------+--------------------------------------+--------+
$ f2 -f '.*' -r '10%03d<15-17>_{{f}}{{ext}}'
+----------------------------------+--------------------------------------+--------+
| INPUT | OUTPUT | STATUS |
+----------------------------------+--------------------------------------+--------+
| alternatives.log | 010_alternatives.log | ok |
| auth.log | 011_auth.log | ok |
| dpkg.log | 012_dpkg.log | ok |
| error.log | 013_error.log | ok |
| fontconfig.log | 014_fontconfig.log | ok |
| history.log | 018_history.log | ok |
| kern.log | 019_kern.log | ok |
| mongod.log | 020_mongod.log | ok |
| postgresql-12-main.log | 021_postgresql-12-main.log | ok |
| sysinfo.log | 022_sysinfo.log | ok |
| term.log | 023_term.log | ok |
| unattended-upgrades-shutdown.log | 024_unattended-upgrades-shutdown.log | ok |
+----------------------------------+--------------------------------------+--------+
$ f2 -f '.*' -r '50%dr3<15-17>_{{f}}{{ext}}'
+----------------------------------+------------------------------------------+--------+
| INPUT | OUTPUT | STATUS |
+----------------------------------+------------------------------------------+--------+
| alternatives.log | L_alternatives.log | ok |
| auth.log | LIII_auth.log | ok |
| dpkg.log | LVI_dpkg.log | ok |
| error.log | LIX_error.log | ok |
| fontconfig.log | LXII_fontconfig.log | ok |
| history.log | LXV_history.log | ok |
| kern.log | LXVIII_kern.log | ok |
| mongod.log | LXXI_mongod.log | ok |
| postgresql-12-main.log | LXXIV_postgresql-12-main.log | ok |
| sysinfo.log | LXXVII_sysinfo.log | ok |
| term.log | LXXX_term.log | ok |
| unattended-upgrades-shutdown.log | LXXXIII_unattended-upgrades-shutdown.log | ok |
+----------------------------------+------------------------------------------+--------+
$ f2 -f '.*' -r '%db3<1-3>_{{f}}_%04d{{ext}}'
+----------------------------------+----------------------------------------------+--------+
| INPUT | OUTPUT | STATUS |
+----------------------------------+----------------------------------------------+--------+
| alternatives.log | 100_alternatives_0001.log | ok |
| auth.log | 111_auth_0002.log | ok |
| dpkg.log | 1010_dpkg_0003.log | ok |
| error.log | 1101_error_0004.log | ok |
| fontconfig.log | 10000_fontconfig_0005.log | ok |
| history.log | 10011_history_0006.log | ok |
| kern.log | 10110_kern_0007.log | ok |
| mongod.log | 11001_mongod_0008.log | ok |
| postgresql-12-main.log | 11100_postgresql-12-main_0009.log | ok |
| sysinfo.log | 11111_sysinfo_0010.log | ok |
| term.log | 100010_term_0011.log | ok |
| unattended-upgrades-shutdown.log | 100101_unattended-upgrades-shutdown_0012.log | ok |
+----------------------------------+----------------------------------------------+--------+