0

I have a file named(multi_extension123.txt). Before copying this file into the directory I need to remove files like [multi_extension1234.txt multi_extension1234.txt multi_extension12345.txt] if present in the directory and then copy the earlier one to this directory. Can anyone give the solution with shellscript.

note: i need to remove only numerical numbers and extension alone.

I have tried this

$ filename= $file1

$ echo "${filename%[0-9].*}"

find . -type f maxdepth 0 mindepth 0 -name "'$filename'[0-9]*.txt" -exec rm -f {} \;

Armali
  • 18,255
  • 14
  • 57
  • 171
Tehniyat
  • 1
  • 1
  • 3
    The goal is that you add some code of your own to show at least the research effort you made to solve this yourself. – Cyrus Jan 11 '18 at 05:33
  • Regex comes to mind. – lofihelsinki Jan 11 '18 at 05:39
  • I'd suggest starting with [BashFAQ #100](http://mywiki.wooledge.org/BashFAQ/100) (*How can I do string manipulations in bash?*), which covers everything needed. – Charles Duffy Jan 11 '18 at 06:05
  • BTW, note that the two flagged duplicates are intended to be used together. One tells you how to extract only the basename (removing the extension, in this case `.txt`); the other tells you how to extract only the non-numeric part of that basename. (Granted, the OP there is using that result for a `mv` command, but there's no obligation to apply it the same way). – Charles Duffy Jan 11 '18 at 06:07

0 Answers0