You are not logged in.

#1 2020-10-23 01:54:41

amaro
Member
From: xfce
Registered: 2014-05-09
Posts: 367

[SOLVED] remove timestamps from hundreds of txt files

Hello everybody,

I used to use 'scribes' for txt files but now it's unmaintained for more than a year.

I have a folder of hundered of txt files that look like this 'browse_reddit_at_work_pretending_you_are_doing_something_important_2019_04-24_210459'.

In fact 'scribes' initially saved them as 'browse reddit at work pretending you are doing something important (2019 04-24 210459)'

I have a script to modify the titles a bit but the timestamps remain.

How to remove all the timestamps at the end of those files?

Thank you in advance!

p.s. I have no programming skills. The script I mentioned I have is from Arch forum.

Last edited by amaro (2020-10-23 12:18:41)

Offline

#2 2020-10-23 06:05:17

solskog
Member
Registered: 2020-09-05
Posts: 462

Re: [SOLVED] remove timestamps from hundreds of txt files

If you don't mind use perl parallel that is pretty fast. And how do you keep a unique file name without timestamps? This little bash/perl function assume you have unique filenames.

# pacman -S parallel
timestamps ()
{
    local name='something_important_2019_04-24_210459';
    local dir=${1:?[directory]};
    [[ -d $dir ]] || return 1;
    /usr/sbin/perl - "${dir}" <<'PERLMV' |
    use v5.32.0;
    use warnings;
    use File::Find;
    my @Files;
    my ($dir) = @ARGV;
    my ($j,$source,$target) = (0,"","");
    sub insert
    {
        if(-d){
            return;
        }else{
            $source = "$File::Find::name";
            $target = $source =~ s;(.*)_\d+_\d\d-\d\d_\d+;$1;r;
            $Files[$j++] = "mv $source $target\n";
        }
    }
    find(\&insert,$dir);
    say @Files
PERLMV
  /usr/sbin/parallel -j 4 --will-cite
}

Last edited by solskog (2020-10-23 08:00:22)

Offline

#3 2020-10-23 06:10:09

Awebb
Member
Registered: 2010-05-06
Posts: 6,688

Re: [SOLVED] remove timestamps from hundreds of txt files

What you want to do is called a "batch rename" or a "bulk rename". Look up both terms in the pacman repos and the AUR. There must be one tool that meets your needs.

However, this would be the perfect opportunity to learn some shell scripting.

Offline

#4 2020-10-23 06:30:53

jonno2002
Member
Registered: 2016-11-21
Posts: 897

Re: [SOLVED] remove timestamps from hundreds of txt files

thunar file manager has a good batch renamer built in:
https://docs.xfce.org/xfce/thunar/bulk-renamer/start

Offline

#5 2020-10-23 08:09:15

d_fajardo
Member
Registered: 2017-07-28
Posts: 1,687

Re: [SOLVED] remove timestamps from hundreds of txt files

Easily doable in python too.

Offline

#6 2020-10-23 12:30:27

amaro
Member
From: xfce
Registered: 2014-05-09
Posts: 367

Re: [SOLVED] remove timestamps from hundreds of txt files

Thank you, guys!

Used Thunar's renamer as jonno2002 suggested. Worked fine.
(Have never used it before)

Offline

Board footer

Powered by FluxBB