Существует ли буквенный эквивалент nl или seq?

Sí.

smartctl. Ver la -topción

-t TEST, --test=TEST
  Executes TEST immediately. The '-C' option can be used in conjunction with 
  this option to run the short or long (and also for ATA devices, selective or 
  conveyance) self-tests in captive mode (known as "foreground mode" for SCSI 
  devices). Note that only one test type can be run at a time, so only one 
  test type should be specified per command line. Note also that if a computer 
  is shutdown or power cycled during a self-test, no harm should result. The 
  self-test will either be aborted or will resume automatically.
  [...]

Página del manual enhttps://linux.die.net/man/8/smartctl

1
15.06.2019, 15:42
4 ответа

С bashс использованием paste, head, wcиprintf:

# generate somefile
$ printf 'line %s of file\n' {1..5} > somefile

# then paste
$ paste -d ' ' <(printf '%s\n' {a..z}) somefile
a line 1 of file
b line 2 of file
c line 3 of file
d line 4 of file
e line 5 of file
f
g
...

Поскольку мы не знаем, сколько символов нам нужно сгенерировать(a-eв этом примере ), мы могли бы сгенерировать полный алфавит и объединить только столько строк, сколько есть somefile, и записать это как функцию:

function abc() { paste -d ' ' <(printf '%s\n' {a..z} | head -n $(wc -l <"$1")) "$1"; }

Выход:

$ abc somefile
a line 1 of file
b line 2 of file
c line 3 of file
d line 4 of file
e line 5 of file
1
27.01.2020, 23:17

Вы можете использовать awk:

awk '{printf "%c\t%s\n", NR+96, $0}'

(97 — десятичное значение ASCIIa)

% seq 1 10 |  awk '{printf "%c\t%s\n", NR+96, $0}'   
a       1
b       2
c       3
d       4
e       5
f       6
g       7
h       8
i       9
j       10
3
27.01.2020, 23:17

В bash для печати любого диапазона символов, а не только буквенных или цифровых:

$ printf '%b\n' "$(eval printf '\\%03o' $(printf '{%d..%d}' "'!" "'~"))"
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
0
27.01.2020, 23:17

Perl знает, как увеличивать строки, включая «z» -> «aa» и т. д. Попробуйте это:

# a bash function for "alphabetic nl"
anl() {
    perl -sne 'printf "%6s\t%s", $nl++, $_' -- -nl=a "$@"
}

Тогда можно

seq 50 | anl
anl file file...
0
27.01.2020, 23:17

Теги

Похожие вопросы