In your loop, you can do the following for each file:
# delete first five characters
name=${file:5}
# delete .tar.gz suffix
name=${file%%.tar.gz}
Pregunta
i have this little code here
for file in *.tar.gz;
do tar xzvf "${file}" && rm "${file}";
done
It extracts a tar.gz and deletes it. Now I have to create a filelist file (.fl) named like a substring from the .tar . For example, I have to delete the first 5 letters and the last 5 (the extension) from the name of the .tar.gz . And that for every .tar.gz that I extract.
Example:
Thanks in advance.
Solución
In your loop, you can do the following for each file:
# delete first five characters
name=${file:5}
# delete .tar.gz suffix
name=${file%%.tar.gz}
Otros consejos
Use
for file in *.tar.gz
do
# this creates the file list into a .fl file:
tar tfz "${file}" > "${file:5:-5}.fl"
# this extracts and afterwards removes the tar archive:
tar xzvf "${file}" && rm "${file}"
done
You also can combine the two in one step:
for file in *.tar.gz
do
tar xzvf "${file}" > "${file:5:-5}.fl" && rm "${file}"
done