Considerando qualquer nome de arquivo possível, desse diretório:
printf '%sprintf '%sprintf '%s\n' cpu-*-201* | grep -Po '^.*(?=-201)' | sort -u
' cpu-*-201* | \
awk -F'-' 'BEGIN{RS="printf '%s\n' cpu-*-201* | sed -E 's/^(.*)-201.*//' | sort -u
"} $3~/^201/ {print $1"-"$2}' | sort -u
' cpu-*-201* | \
awk -F'-' 'BEGIN{RS="printf '%s\n' cpu-*-201* | awk -F'-' '$3~/^201/ {a[$1"-"$2]} END{for(i in a) print i}'
printf '%s\n' cpu-*-201* | awk -F'-' '$3~/^201/ {print $1"-"$2}' | sort -u
"} $3~/^201/ {a[$1"-"$2]} END{for(i in a) print i}'
-
printf '%sawk
' cpu-*-201*
imprime os nomes dos arquivos separados por NUL
-
-
define o separador de registro como NUL e coloca os dois primeiros campos -
separados (com a
entre) como chave da matriz associativa 201
, se o terceiro campo for iniciado com {a[$1"-"$2]} END{for(i in a) print i}
. No final, estamos apenas imprimindo as chaves do array com sort
Se quiser, você pode se livrar da matriz e aproveitar -
depois de imprimir os dois primeiros campos separados por sort -u
:
printf '%s\n' cpu-*-201* | cut -d- -f1,2 | sort -u
Assumindo que nenhum nome de arquivo incomum, há muitas opções, todas com ajuda de grep
para obter exclusividade:
-
sed
, com PCRE:
% printf '%s\n' cpu-*-201*
cpu-interrupt-2016-05-07
cpu-interrupt-2017-05-08
cpu-softirq-2017-05-06
cpu-softirq-2017-05-07
cpu-softirq-2017-05-08
cpu-system-2016-05-06
cpu-system-2017-05-08
cpu-wait-2016-05-06
cpu-wait-2017-05-07
cpu-wait-2017-05-08
% printf '%sprintf '%sprintf '%sprintf '%s\n' cpu-*-201* | grep -Po '^.*(?=-201)' | sort -u
' cpu-*-201* | \
awk -F'-' 'BEGIN{RS="printf '%s\n' cpu-*-201* | sed -E 's/^(.*)-201.*//' | sort -u
"} $3~/^201/ {print $1"-"$2}' | sort -u
' cpu-*-201* | \
awk -F'-' 'BEGIN{RS="printf '%s\n' cpu-*-201* | awk -F'-' '$3~/^201/ {a[$1"-"$2]} END{for(i in a) print i}'
printf '%s\n' cpu-*-201* | awk -F'-' '$3~/^201/ {print $1"-"$2}' | sort -u
"} $3~/^201/ {a[$1"-"$2]} END{for(i in a) print i}'
' cpu-*-201* | awk -F'-' 'BEGIN{RS="printf '%s\n' cpu-*-201* | cut -d- -f1,2 | sort -u
"} $3~/^201/ {a[$1"-"$2]} END{for(i in a) print i}'
cpu-softirq
cpu-interrupt
cpu-wait
cpu-system
% printf '%s% printf '%s\n' cpu-*-201*
cpu-interrupt-2016-05-07
cpu-interrupt-2017-05-08
cpu-softirq-2017-05-06
cpu-softirq-2017-05-07
cpu-softirq-2017-05-08
cpu-system-2016-05-06
cpu-system-2017-05-08
cpu-wait-2016-05-06
cpu-wait-2017-05-07
cpu-wait-2017-05-08
% printf '%s%pre%' cpu-*-201* | awk -F'-' 'BEGIN{RS="%pre%"} $3~/^201/ {a[$1"-"$2]} END{for(i in a) print i}'
cpu-softirq
cpu-interrupt
cpu-wait
cpu-system
% printf '%s%pre%' cpu-*-201* | awk -F'-' 'BEGIN{RS="%pre%"} $3~/^201/ {print $1"-"$2}' | sort -u
cpu-interrupt
cpu-softirq
cpu-system
cpu-wait
% printf '%s\n' cpu-*-201* | grep -Po '^.*(?=-201)' | sort -u
cpu-interrupt
cpu-softirq
cpu-system
cpu-wait
% printf '%s\n' cpu-*-201* | sed -E 's/^(.*)-201.*//' | sort -u
cpu-interrupt
cpu-softirq
cpu-system
cpu-wait
% printf '%s\n' cpu-*-201* | awk -F'-' '$3~/^201/ {a[$1"-"$2]} END{for(i in a) print i}'
cpu-interrupt
cpu-softirq
cpu-system
cpu-wait
% printf '%s\n' cpu-*-201* | awk -F'-' '$3~/^201/ {print $1"-"$2}' | sort -u
cpu-interrupt
cpu-softirq
cpu-system
cpu-wait
% printf '%s\n' cpu-*-201* | cut -d- -f1,2 | sort -u
cpu-interrupt
cpu-softirq
cpu-system
cpu-wait
' cpu-*-201* | awk -F'-' 'BEGIN{RS="%pre%"} $3~/^201/ {print $1"-"$2}' | sort -u
cpu-interrupt
cpu-softirq
cpu-system
cpu-wait
% printf '%s\n' cpu-*-201* | grep -Po '^.*(?=-201)' | sort -u
cpu-interrupt
cpu-softirq
cpu-system
cpu-wait
% printf '%s\n' cpu-*-201* | sed -E 's/^(.*)-201.*//' | sort -u
cpu-interrupt
cpu-softirq
cpu-system
cpu-wait
% printf '%s\n' cpu-*-201* | awk -F'-' '$3~/^201/ {a[$1"-"$2]} END{for(i in a) print i}'
cpu-interrupt
cpu-softirq
cpu-system
cpu-wait
% printf '%s\n' cpu-*-201* | awk -F'-' '$3~/^201/ {print $1"-"$2}' | sort -u
cpu-interrupt
cpu-softirq
cpu-system
cpu-wait
% printf '%s\n' cpu-*-201* | cut -d- -f1,2 | sort -u
cpu-interrupt
cpu-softirq
cpu-system
cpu-wait
-
awk
:
%pre%
-
cut
:
%pre%
-
%code% , assumindo campos estáveis, isso está ficando cegamente os dois primeiros campos :
%pre%
Exemplo:
%pre%