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?

9
  • 2
    Wrong rename utility? See Why is the rename utility on Debian/Ubuntu different than the one on other distributions, like CentOS? and check what rename --version says.
    – ilkkachu
    Sep 6, 2018 at 8: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 6, 2018 at 8: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 6, 2018 at 8:29
  • Sorry, I re-edited the comment. But what is the precise output when it doesn't work?
    – Sparhawk
    Sep 6, 2018 at 8:31
  • 1
    @GAD3R Your command also doesn't work. :(
    – The One
    Sep 6, 2018 at 8:31

1 Answer 1

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
2
  • Just started using the {...} expansions in some of my scripts. It's much faster than spawning a new process with $(...)
    – user208145
    Sep 6, 2018 at 9:27
  • 1
    @Kamaraj s/cp/mv/
    – Siva
    Sep 6, 2018 at 9:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .