Skip to main content
added 43 characters in body; edited tags
Source Link
terdon
  • 252.7k
  • 69
  • 481
  • 719

I gothave a bunch of files that iI have to process, the on a Linux machine. The files look like this:

2009-08-18T034353_DR1_4N-NAC_123456_1234_band1.ntf
2009-08-18T034353_DR1_4N-NAC_123456_1234_browse.jpg
2009-08-18T034353_DR1_4N-NAC_123456_1234_band2.ntf
2009-08-18T034353_DR1_4N-NAC_123456_1234_license.txt
2009-08-18T034353_DR1_4N-NAC_123456_1234_metadata.xml
2009-08-18T034353_DR1_4N-NAC_123456_1234_readme.txt
2009-08-18T034353_DR1_4N-NAC_123456_1234_udm.tif

2009-08-18T034353_DR1_4N-NAC_123456_1234_band1.ntf 2009-08-18T034353_DR1_4N-NAC_123456_1234_browse.jpg 2009-08-18T034353_DR1_4N-NAC_123456_1234_band2.ntf 2009-08-18T034353_DR1_4N-NAC_123456_1234_license.txt 2009-08-18T034353_DR1_4N-NAC_123456_1234_metadata.xml 2009-08-18T034353_DR1_4N-NAC_123456_1234_readme.txt 2009-08-18T034353_DR1_4N-NAC_123456_1234_udm.tif 

I want to delete this part: "-NAC_123456_1234"-NAC_123456_1234 where the first part can consist of alphanumeric characters and the number parts only of numeric characters.

I tried to a rename command but i wontcouldn't get it to work,. I thought of something like:

rename '/-[a-zA-Z]+_[0-9]+_[0-9]+//' *.*

rename '/-[a-zA-Z]+_[0-9]+_[0-9]+//' *.* 

Someone canCan someone help me with what iI am missing? My

My rename version is: rename from util-linux 2.23.2

rename from util-linux 2.23.2 

I got a bunch of files that i have to process, the files look like this:

2009-08-18T034353_DR1_4N-NAC_123456_1234_band1.ntf
2009-08-18T034353_DR1_4N-NAC_123456_1234_browse.jpg
2009-08-18T034353_DR1_4N-NAC_123456_1234_band2.ntf
2009-08-18T034353_DR1_4N-NAC_123456_1234_license.txt
2009-08-18T034353_DR1_4N-NAC_123456_1234_metadata.xml
2009-08-18T034353_DR1_4N-NAC_123456_1234_readme.txt
2009-08-18T034353_DR1_4N-NAC_123456_1234_udm.tif

I want to delete this part: "-NAC_123456_1234" where the first part can consist of alphanumeric characters and the number parts only of numeric characters.

I tried to a rename command but i wont get it to work, thought of something like:

rename '/-[a-zA-Z]+_[0-9]+_[0-9]+//' *.*

Someone can help me with what i am missing? My rename version is: rename from util-linux 2.23.2

I have a bunch of files that I have to process on a Linux machine. The files look like this:

2009-08-18T034353_DR1_4N-NAC_123456_1234_band1.ntf 2009-08-18T034353_DR1_4N-NAC_123456_1234_browse.jpg 2009-08-18T034353_DR1_4N-NAC_123456_1234_band2.ntf 2009-08-18T034353_DR1_4N-NAC_123456_1234_license.txt 2009-08-18T034353_DR1_4N-NAC_123456_1234_metadata.xml 2009-08-18T034353_DR1_4N-NAC_123456_1234_readme.txt 2009-08-18T034353_DR1_4N-NAC_123456_1234_udm.tif 

I want to delete this part: -NAC_123456_1234 where the first part can consist of alphanumeric characters and the number parts only of numeric characters.

I tried a rename command but couldn't get it to work. I thought of something like:

rename '/-[a-zA-Z]+_[0-9]+_[0-9]+//' *.* 

Can someone help me with what I am missing?

My rename version is:

rename from util-linux 2.23.2 
Source Link
Nunkuat
  • 203
  • 1
  • 5

Rename files using regex to delete part of name

I got a bunch of files that i have to process, the files look like this:

2009-08-18T034353_DR1_4N-NAC_123456_1234_band1.ntf
2009-08-18T034353_DR1_4N-NAC_123456_1234_browse.jpg
2009-08-18T034353_DR1_4N-NAC_123456_1234_band2.ntf
2009-08-18T034353_DR1_4N-NAC_123456_1234_license.txt
2009-08-18T034353_DR1_4N-NAC_123456_1234_metadata.xml
2009-08-18T034353_DR1_4N-NAC_123456_1234_readme.txt
2009-08-18T034353_DR1_4N-NAC_123456_1234_udm.tif

I want to delete this part: "-NAC_123456_1234" where the first part can consist of alphanumeric characters and the number parts only of numeric characters.

I tried to a rename command but i wont get it to work, thought of something like:

rename '/-[a-zA-Z]+_[0-9]+_[0-9]+//' *.*

Someone can help me with what i am missing? My rename version is: rename from util-linux 2.23.2