I have many files that have the same prefix, only the bit after the underscore is different. And I have many prefixes as well! Underscore does not appear anywhere else in th
I had a similar problem, had many files and wanted to group and cat them by prefix, I used this little script:
ls | awk -F '_' '!x[$1]++{print $1}' | while read -r line
do
cat $line* > all_$line\.txt
done
ls will show all the files in the directory
In awk the -F '_' option is to set the underscore as the delimiter, and the code itself acts like uniq, meaning will print each prefix only once.
Then we run a loop on all prefixes and cat all the files with the same prefix.