-1

I have following files with names like:

Selection_Test_from_120118_1140118.txt
Selection_Test_from_monthly_120118_1140118.txt

how we can rename both files by removing string from file:

string1 --> Selection_Test.txt (remove "_from_120118_1140118")
string2 --> Selection_Test.txt (remove "_from_monthly_120118_1140118")

I want to use parameter expansion method instead of traditional cut command here

Sparhawk
  • 19,561
  • 18
  • 86
  • 152
Rocky86
  • 501
  • 1
  • 9
  • 16

1 Answers1

1

With Perl's standalone rename command:

rename -n 's/_from_[^.]*//' *.txt

If everything looks okay, remove -n.

Cyrus
  • 12,059
  • 3
  • 29
  • 53