9
votes
How can I find common prefixes in file names to group them?
With perl:
$ find . -print0 | perl -C -l -0ne '
if (m{/([^/]{4,}?\w)\b[^/]*\z}) {
push @{$list{$1}}, $_;
}
END {
while (($part, $list) = each(%list)) {
if (($count = @$list) > 1)...
5
votes
Accepted
Help w/ "posix-extended" regex for 'find'
If you have zsh, you don't need find (and BTW, FreeBSD's find is not old, it's just a different implementation from the GNU one, where extended regexps is just with -E like in grep or sed).
find . -...
4
votes
Help w/ "posix-extended" regex for 'find'
In addition to @muru's answer pointing out that find doesn't support \s (so you need to use [:space:] instead):
Instead of A-Za-z, you can use the posix character class [:alpha:], and instead of A-Za-...
3
votes
How can I find common prefixes in file names to group them?
If you only accept the string to end at a word border then this gives you the potential common strings; tune that to your requirements:
sed -n '/^\(\w\+ \w\+\) /s/^\(\w\+ \w\+\) .*$/\1/p' file
Then ...
3
votes
Help w/ "posix-extended" regex for 'find'
Two things:
\s is not supported by GNU find. There are \w and \W for word and non-word, but no \s. See the documentation. Also: Why does my regular expression work in X but not in Y? on why the ...
2
votes
How can I find common prefixes in file names to group them?
Using Raku (formerly known as Perl_6)
Raku regex below groups filenames by starting characters: minimum 3-or-more <alpha> characters followed by \h horizontal whitespace or _ underscore:
~$ ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
find × 3608bash × 683
linux × 461
shell-script × 377
shell × 370
grep × 369
files × 354
command-line × 205
xargs × 178
directory × 147
regular-expression × 143
ls × 135
sed × 134
rm × 123
filenames × 117
rename × 112
wildcards × 96
awk × 93
mv × 90
scripting × 89
macos × 84
permissions × 74
recursive × 74
cp × 72
pipe × 69