Retain only part of a file name and fasta header in fasta directory I have a MainDirectory/hundreds_of_subdirectories/thousands_of_fastas structure. For each fasta in the bottom level, I am trying to change the file name as well as the first line in the file to retain only some parts of the file.
So that the following text, which makes up both the file name and the first name of the file:
947-length-1150-cov-1000|contig:JAECWU010000213.1|slice:817050-818200|uce:uce-1452|match:817550-817700|orient:{'+'}|probes:4.unaligned.fasta

becomes just:
uce-1452.unaligned.fasta

For editing the first line in the file, I have tried
sed '1 s/^[^|uce-]*(|uce-[0-9]).*/\1/' hundreds_of_subdirectories/*

but this isn't the ticket..
Then messing around with some kind of loop...
for i in *\*.unaligned.fasta
do
  sed -E 's/^[^|uce-]*(|uce-[0-9]).*/\1/'
done

For the file name, it was suggested that I use rename instead of sed, but with sed I have tried something like:
for x in hundreds_of_subdirectories/thousands_of_fastas*unaligned.fasta
do
  echo $x | sed -r 's/^[^|uce-]*(|uce-[0-9]).*/mv' -v &quot;\0&quot; &quot;|uce-[0-9].*/\1/.unaligned.fasta&quot;/
done

Am I even barking up the right tree? Thanks!
I think you're working too hard to capture the uce: expression.
Try
sed -Ee '1s/^.+uce:(uce-[0-9]+).+/\1.unaligned.fasta/' file_glob

to replace the first line content. You may want to add the in-place flag after testing the expression on a few files.
For the mv, use command substitution, which runs the command in a sub-shell and uses the output value as the parameter:
for f in file_glob
do    
    mv -- &quot;$f" "$(echo \&quot;$f\&quot; | sed '...')&quot;
done