Removing characters from beginning of multiple files

Hi,

I have been searching how to do this but I can't seem to find how to do it. Hopefully someone can help.

I have multiplr files, 100's example 12345-zxys.213423.zyz.txt. I want to be able to take all these files and remove the first '12345-' from each of the files. '12345-' these characters are uniqe on each file but of the same length.

I would appreciate if someone can help.

Thanks in advance.

Regards
Israr

Please post what have you tried, where are you struck.

Here is a sample.

ls 12345-zxys.213423.zyz.txt | while read file
do
newfilename=`echo $file | sed 's/^.*-//'`
mv $file $newfilename
done
1 Like

hi matrixmadhan,

Thank you so much for quick response. If I run this will it only do fir single file or will it for the batch?

I have added sample script for a single file, please change it to multiple files like

ls file*

Please give it a try and let us know if there are any problems.

1 Like

Yes thats worked exactly as I wanted. so I replaced ls file* with ls *.txt. For benefit of many who have not used sed command and learning. can you please break the command down?

Many thx

You might want to consider shell's parameter expansion (no external cammnd like sed necessary):

for FN in *.txt; do echo mv $FN ${FN#*-}; done
1 Like