1

I have some text file like this

access-2018-08-21.log.1-20180906
access-2018-08-22.log.1-20180906

I want to remove the -20180906 part wo the result would be

access-2018-08-21.log
access-2018-08-22.log

I tried rename -- "s/\-20180906//g" * but it didn't work.

What's the command line i need to achieve my goal?

The One
  • 4,662
  • 11
  • 29
  • 35
  • 2
    Wrong `rename` utility? See [Why is the rename utility on Debian/Ubuntu different than the one on other distributions, like CentOS?](https://unix.stackexchange.com/q/275254/170373) and check what `rename --version` says. – ilkkachu Sep 06 '18 at 08:26
  • 1
    Does not work in what way? Also, your command is a bit wrong. Something like the following suffices: `rename "s/\.1-20180906//g" *` – Sparhawk Sep 06 '18 at 08:26
  • Hi, it didn't work in a way that doesn't remove the -20180906 part. And by the way, your above-mentioned command also doesn't remove the -20180906 part. – The One Sep 06 '18 at 08:29
  • Sorry, I re-edited the comment. But what is the precise output when it doesn't work? – Sparhawk Sep 06 '18 at 08:31
  • 1
    @GAD3R Your command also doesn't work. :( – The One Sep 06 '18 at 08:31
  • @Sparhawk It didn't have any output. After executing your command, i used ls to check and the file name still remained. – The One Sep 06 '18 at 08:33
  • Thanks. And as per the other comment, what is the output of `rename --version`? – Sparhawk Sep 06 '18 at 08:33
  • Here's the output rename from util-linux 2.30.2 – The One Sep 06 '18 at 08:34
  • Okay, thanks. So @ikkachu's link is spot on. Have a read of that. You need the perl version of rename instead. – Sparhawk Sep 06 '18 at 08:35

1 Answers1

1

Try this..

if you are happy with the output, then just remove the echo word.

for i in access*; do echo mv $i ${i%.*}; done
Kamaraj
  • 4,295
  • 1
  • 12
  • 18