renaming multiple files with first line of content

Hi ,
I want to rename multiple files with their first line bar the first character + the extension .qual. For the example below the filename should read
7180000000987.qual. I have trawled through different threads for 2 days and I don't seem to find anything I can adopt for this task :confused:

>7180000000987
60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60
60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60
60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60
60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60
60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60
60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60

Your help would be very much appreciated

Bruno

Something like this:

find . -type f -name *.input -print | while read FILE
do
    echo mv "$FILE" "$( dirname "$FILE" )"/"$( head -1 "$FILE" | cut -c2- )".qual
done

Change the search instructions for find as needed, and when satisfied with the result, remove the echo from inside the loop.

for file in *  ## adjust pattern (*) as necessary
do
  read line < "$file"
  mv "$file" "${line#?}.qual"
done

you are supposed to read up to gain knowledge in the first place. Also, renaming files, reading files are so common that its just not possible not to find it here.. Note you can't really find exactly solutions to your problems because all problems are different but i am sure you can find similar ones....
that said, if you are using bash, for one file

read line < "filename"
newfilename=${line/>/}
mv "filename" "$newfilename"

use a for loop to go over multiple files

It is probably good practice to validate your read from the file prior to doing the move, checking for things like spaces and nulls in the new name. Also check if the new file exists before doing the move. It would be easy to end up with 1 file called: -

60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60.qual

That's a valid (but inadvisable) filename, though given the OP's requirement, it would be:

0 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60.qual

:slight_smile: True

Although he didn't say he wanted to overwrite all files with successive moves and end up with 1 file!! LOL

Thanks for all your help I got it sorted :slight_smile: