Hello friends,
I have around 1000 files in a directory with different kind of file names like Championships-2009--How-to-get-in-27781, wiki1.jpg,used_shutterstock_2881985_4.jpg,stock-43047295.jpg, corporate-hospitality---19538 etc.
I need a script which can replace only one - (dash) near to digits only from those files names which are ending with only digits.
Like Championships-2009--How-to-get-in-27781 to Championships-2009--How-to-get-in_27781 and corporate-hospitality---19538 to corporate-hospitality--_19538
echo "Championships-2009--How-to-get-in-27781" | sed 's/\(.*\)-\([0-9].*\)/\1_\2/'
echo "corporate-hospitality---19538" | sed 's/\(.*\)-\([0-9].*\)/\1_\2/'
That's incorrect. The * allows a string of arbitrary length and of arbitrary characters to follow a digit. It will absolutely not insure that the name matched ends with digits.
Thanks for reply.
I think you misunderstood my question. I want to replace only one - with _ of file names, like Time-to-Panic--585 . It should change to Time-to-Panic-_5852 and there are more that 1000 files in a directory with various name patterns, like sharp3dphone--2_0.jpeg, Paying-the-piper-6091--big, Z06-Corvette--4471 etc. So i need a script which can find out only those files whose names are ending with -[0-9] pattern and replace only one - with _ it means -[0-9] to _[0-9].