The task is, to list all file names from a directory, that contains the same letters, only difference is the order of the letters like asd.txt and dsa.txt
There is a working code in powershell:
for i in `ls -v $dir`;
do
temp=$(grep -o . <<<"$i"|sort|tr -d "\n")
temper=$i
for j in `ls -v $dir`;
do
temp2=$(grep -o . <<<"$j"|sort|tr -d "\n")
if [ "$temp" = "$temp2" ] && [ "$temper" != "$j" ];
then
echo $temper
echo $j
fi
done;
done;
That is an almost working code, problem is that list proper files 2 times, any idea to correct it?
bash
This will break for files with whitespace in the name:
Testing in a directory with files
asdf.txt
,fdsa.txt
,foo
,foobar
,tadxfst.
Depending what you're doing with the groups, I'd use something like perl: