Removing digits from beginning of filename
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I was hoping this would work:
$ find . -type f -exec basename ; | while EFS= read -r f; do echo "$f##[0-9]"; done
But, for example, for files named as:
1foo
11bar
it returns:
foo
1bar
when
foo
bar
is expected.
PS: ultimately, I want to mv "$f"
to the modified name (and also do other modifications)
find rename parameter
 |Â
show 1 more comment
up vote
0
down vote
favorite
I was hoping this would work:
$ find . -type f -exec basename ; | while EFS= read -r f; do echo "$f##[0-9]"; done
But, for example, for files named as:
1foo
11bar
it returns:
foo
1bar
when
foo
bar
is expected.
PS: ultimately, I want to mv "$f"
to the modified name (and also do other modifications)
find rename parameter
1
Your code is telling it , in effect, to remove 0-9 from the beginning of the filename. If there is more than one digit (two, for example) then you need to change[0-9]
to[0-99]
. For three, you need[0-999]
and so on and so forth.
â Nasir Riley
11 mins ago
The title says "beginning of file" but your code is gathering filenames and then renaming them. Also, unsetting "EFS" appears to be a typo for unsetting "IFS"
â Jeff Schaller
6 mins ago
Your solution necessitates to know in advance the number of digits. Is there not a more general way? Why doesn't##
take care of it in the parameter expansion?
â Erwann
6 mins ago
Yes, I meant filename, sorry.
â Erwann
5 mins ago
1
Do you care how it's done? Do you have a "rename" utility installed?
â Jeff Schaller
4 mins ago
 |Â
show 1 more comment
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I was hoping this would work:
$ find . -type f -exec basename ; | while EFS= read -r f; do echo "$f##[0-9]"; done
But, for example, for files named as:
1foo
11bar
it returns:
foo
1bar
when
foo
bar
is expected.
PS: ultimately, I want to mv "$f"
to the modified name (and also do other modifications)
find rename parameter
I was hoping this would work:
$ find . -type f -exec basename ; | while EFS= read -r f; do echo "$f##[0-9]"; done
But, for example, for files named as:
1foo
11bar
it returns:
foo
1bar
when
foo
bar
is expected.
PS: ultimately, I want to mv "$f"
to the modified name (and also do other modifications)
find rename parameter
find rename parameter
edited 1 min ago
Jeff Schaller
34.4k951114
34.4k951114
asked 1 hour ago
Erwann
268
268
1
Your code is telling it , in effect, to remove 0-9 from the beginning of the filename. If there is more than one digit (two, for example) then you need to change[0-9]
to[0-99]
. For three, you need[0-999]
and so on and so forth.
â Nasir Riley
11 mins ago
The title says "beginning of file" but your code is gathering filenames and then renaming them. Also, unsetting "EFS" appears to be a typo for unsetting "IFS"
â Jeff Schaller
6 mins ago
Your solution necessitates to know in advance the number of digits. Is there not a more general way? Why doesn't##
take care of it in the parameter expansion?
â Erwann
6 mins ago
Yes, I meant filename, sorry.
â Erwann
5 mins ago
1
Do you care how it's done? Do you have a "rename" utility installed?
â Jeff Schaller
4 mins ago
 |Â
show 1 more comment
1
Your code is telling it , in effect, to remove 0-9 from the beginning of the filename. If there is more than one digit (two, for example) then you need to change[0-9]
to[0-99]
. For three, you need[0-999]
and so on and so forth.
â Nasir Riley
11 mins ago
The title says "beginning of file" but your code is gathering filenames and then renaming them. Also, unsetting "EFS" appears to be a typo for unsetting "IFS"
â Jeff Schaller
6 mins ago
Your solution necessitates to know in advance the number of digits. Is there not a more general way? Why doesn't##
take care of it in the parameter expansion?
â Erwann
6 mins ago
Yes, I meant filename, sorry.
â Erwann
5 mins ago
1
Do you care how it's done? Do you have a "rename" utility installed?
â Jeff Schaller
4 mins ago
1
1
Your code is telling it , in effect, to remove 0-9 from the beginning of the filename. If there is more than one digit (two, for example) then you need to change
[0-9]
to [0-99]
. For three, you need [0-999]
and so on and so forth.â Nasir Riley
11 mins ago
Your code is telling it , in effect, to remove 0-9 from the beginning of the filename. If there is more than one digit (two, for example) then you need to change
[0-9]
to [0-99]
. For three, you need [0-999]
and so on and so forth.â Nasir Riley
11 mins ago
The title says "beginning of file" but your code is gathering filenames and then renaming them. Also, unsetting "EFS" appears to be a typo for unsetting "IFS"
â Jeff Schaller
6 mins ago
The title says "beginning of file" but your code is gathering filenames and then renaming them. Also, unsetting "EFS" appears to be a typo for unsetting "IFS"
â Jeff Schaller
6 mins ago
Your solution necessitates to know in advance the number of digits. Is there not a more general way? Why doesn't
##
take care of it in the parameter expansion?â Erwann
6 mins ago
Your solution necessitates to know in advance the number of digits. Is there not a more general way? Why doesn't
##
take care of it in the parameter expansion?â Erwann
6 mins ago
Yes, I meant filename, sorry.
â Erwann
5 mins ago
Yes, I meant filename, sorry.
â Erwann
5 mins ago
1
1
Do you care how it's done? Do you have a "rename" utility installed?
â Jeff Schaller
4 mins ago
Do you care how it's done? Do you have a "rename" utility installed?
â Jeff Schaller
4 mins ago
 |Â
show 1 more comment
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f477613%2fremoving-digits-from-beginning-of-filename%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
1
Your code is telling it , in effect, to remove 0-9 from the beginning of the filename. If there is more than one digit (two, for example) then you need to change
[0-9]
to[0-99]
. For three, you need[0-999]
and so on and so forth.â Nasir Riley
11 mins ago
The title says "beginning of file" but your code is gathering filenames and then renaming them. Also, unsetting "EFS" appears to be a typo for unsetting "IFS"
â Jeff Schaller
6 mins ago
Your solution necessitates to know in advance the number of digits. Is there not a more general way? Why doesn't
##
take care of it in the parameter expansion?â Erwann
6 mins ago
Yes, I meant filename, sorry.
â Erwann
5 mins ago
1
Do you care how it's done? Do you have a "rename" utility installed?
â Jeff Schaller
4 mins ago