Artificial intelligent assistant

Renaming files by removing compiler stamp Given 1. list of directories, e.g. `dirs="Larry Curly Moe"` 2. compiler vendor, e.g. -gcc-M.N.0 the goal is to sweep through each directory and truncate all file names like so: intel-mkl/2018.1.163-gcc-7.1.0 -> intel-mkl/2018.1.163 exuberant-ctags/5.8-gcc-7.1.0 -> exuberant-ctags/5.8 superlu-dist/5.2.2-gcc-7.2.0-openmpi@3.0.0 -> superlu-dist/5.2.2 What are efficient and robust strategies?

This might work for you:

Start with your sample set of files:


$ find . -type f -name '*-gcc-*'
./intel-mkl/2018.1.163-gcc-7.1.0
./superlu-dist/5.2.2-gcc-7.2.0-openmpi@3.0.0
./exuberant-ctags/5.8-gcc-7.1.0


Here's a script to trim -gcc-* off the end of any filename:


$ cat ex.sh
#!/bin/bash
for i in $(find . -type f -name '*-gcc-*'); do
mv "$i" "$(echo "$i" | sed -e 's/-gcc-.*$//')"
done


Run the script:


$ bash ex.sh


Note that the files no longer contain the -gcc-* suffix:


$ find . -type f
./intel-mkl/2018.1.163
./superlu-dist/5.2.2
./exuberant-ctags/5.8

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 41cf5414167f303c51f8c7cd03924f79