如果它是按字母顺序排列,则使用Sed仅删除文件名中的第一个字符(Using Sed to remove only first character in file name if it's alphabetical)

我在一个文件夹中有一堆文件,我需要用另一个名字复制以防万一,如果文件第一个字符是按字母顺序排列的,那么删除这个字符并保留所有其他字符,不管是数字,字母,特殊标记还是什么。 这么少的exsapmles:

R123456.txt - >应复制为123456.txt

Y1235465.jpeg - >应复制为1235465.jpeg

736628487.txt - >什么都不做

我用过这个命令:

for file in * ; do cp $file $(echo $file |sed 's/[A-Za-z]//g'); done

但这也删除了我想留下的文件扩展名......

br Jii

I have bunch of files in a folder which I need to copy with another name in case, that if file first charcter is alphabetical, then remove this character and leave all other character asis either those are numbers, alphabeticals, special marks or what ever. So few exsapmles:

R123456.txt --> should be copied as 123456.txt

Y1235465.jpeg --> should be copied as 1235465.jpeg

736628487.txt --> do nothing

I have used this command:

for file in * ; do cp $file $(echo $file |sed 's/[A-Za-z]//g'); done

But this removes also file extensions which I would like to leave as is...

br Jii

最满意答案

使用

s/^[A-Za-z]//

在缓冲区的开头有一个单独的字母字符

Use

s/^[A-Za-z]//

At the start of the buffer a single alphabetic character

如果它是按字母顺序排列,则使用Sed仅删除文件名中的第一个字符(Using Sed to remove only first character in file name if it's alphabetical)

我在一个文件夹中有一堆文件,我需要用另一个名字复制以防万一,如果文件第一个字符是按字母顺序排列的,那么删除这个字符并保留所有其他字符,不管是数字,字母,特殊标记还是什么。 这么少的exsapmles:

R123456.txt - >应复制为123456.txt

Y1235465.jpeg - >应复制为1235465.jpeg

736628487.txt - >什么都不做

我用过这个命令:

for file in * ; do cp $file $(echo $file |sed 's/[A-Za-z]//g'); done

但这也删除了我想留下的文件扩展名......

br Jii

I have bunch of files in a folder which I need to copy with another name in case, that if file first charcter is alphabetical, then remove this character and leave all other character asis either those are numbers, alphabeticals, special marks or what ever. So few exsapmles:

R123456.txt --> should be copied as 123456.txt

Y1235465.jpeg --> should be copied as 1235465.jpeg

736628487.txt --> do nothing

I have used this command:

for file in * ; do cp $file $(echo $file |sed 's/[A-Za-z]//g'); done

But this removes also file extensions which I would like to leave as is...

br Jii

最满意答案

使用

s/^[A-Za-z]//

在缓冲区的开头有一个单独的字母字符

Use

s/^[A-Za-z]//

At the start of the buffer a single alphabetic character