найти/обнаружить группы имен файлов

Вы не указали, какую реализацию cron вы используете, однако, по крайней мере, в системах на основе Debian (, где она является производной от Vixie cron IIRC ), это не так. Изman 5 crontab:

       An  active line in a crontab will be either an environment setting or a
       cron command.  The crontab file is parsed from top to  bottom,  so  any
       environment  settings  will affect only the cron commands below them in
       the file.  An environment setting is of the form,

           name = value

       where the spaces around the equal-sign (=) are optional, and any subse‐
       quent non-leading spaces in value will be part of the value assigned to
       name.  The value string may be placed in quotes (single or double,  but
       matching)  to  preserve  leading or trailing blanks. To define an empty
       variable, quotes must be used. The value string is not parsed for envi‐
       ronmental substitutions or replacement of variables, thus lines like

           PATH = $HOME/bin:$PATH

       will not work as you might expect. And neither will this work

           A=1
           B=2
           C=$A $B

       There will not be any subsitution for the defined variables in the last
       value.

       An alternative for setting up the commands path is using the fact  that
       many shells will treat the tilde(~) as substitution of $HOME, so if you
       use bash for your tasks you can use this:

            SHELL=/bin/bash
            PATH=~/bin:/usr/bin/:/bin
0
05.11.2021, 11:11
1 ответ

При получении ответов я также нашел решение. Как @AdminBee упомянул об этом также:

В больших списках результатов из файловой системы вы можете использовать findи xargs, если вы не можете ограничить шаблон поиска (, например :'*.txt' ).

for f in./some/path/*.txt; do gr=${f#*_};gr=${gr%_*}; echo "$gr"; done | sort -u
> ABC
> XYZ

find./ -iname '*.txt' | xargs -n 1 | cut -d '_' -f 2 | sort -u
> ABC
> XYZ
0
05.11.2021, 14:13

Теги

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