Replace underscores for spaces using CLI

Support for Ubuntu and other Desktop Linux distributions
Post Reply
rpgmaker
Posts: 18
Joined: 01 May 2016, 17:06

Replace underscores for spaces using CLI

Post by rpgmaker »

I know there is a function to do the reverse but I want to turn underscores into spaces. I've been playing with several commands trying to accomplish this but I'm ready to give up and ask here :)

This is the first expression I tried:

Code: Select all

filebot -script fn:replace --action test --def "e=_" "r= " /path/files
But it just removes the underscores, the space in "r= " is completely ignored. I tried "r=\ " escaping it but filebot complains that there isn't anything to escape. Also tried "r=\s" but it just replaced the underscore with 's'. I tried many other ridiculous combinations with no luck. I could work around it using "r=[ ]" and then replacing the brackets but it's ridiculous since there must be a way to do this directly. Any help would be appreciated.
User avatar
rednoah
The Source
Posts: 22984
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Replace underscores for spaces using CLI

Post by rednoah »

Looks like name=value pairs are trimmed, so leading/trailing whitespace is automatically removed, making this particular use case somewhat impossible.

This really ugly hack will do though:

Code: Select all

filebot -script fn:replace . --action test --def "e=(.*?)_(.*?)" 'r=$1 $2'
For these kind of simple rename tasks you can probably find specialized tools or shell scripts. :lol:
:idea: Please read the FAQ and How to Request Help.
rpgmaker
Posts: 18
Joined: 01 May 2016, 17:06

Re: Replace underscores for spaces using CLI

Post by rpgmaker »

rednoah wrote:This really ugly hack will do though:

Code: Select all

filebot -script fn:replace . --action test --def "e=(.*?)_(.*?)" 'r=$1 $2'
For these kind of simple rename tasks you can probably find specialized tools or shell scripts. :lol:
It's ugly but it works :)

Which regex "format" does filebot accepts? I ask because while they are all very similar there is a perl regex, php regex, etc.
User avatar
rednoah
The Source
Posts: 22984
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Replace underscores for spaces using CLI

Post by rednoah »

Java Regex => https://docs.oracle.com/javase/8/docs/a ... ttern.html

You'll be hard pressed to find a case where this actually matters though. Regex is pretty standard. :lol:
:idea: Please read the FAQ and How to Request Help.
Kaffe
Posts: 3
Joined: 04 Jun 2016, 06:33

Re: Replace underscores for spaces using CLI

Post by Kaffe »

As you're on Linux, just use the command "rename" instead.

Code: Select all

rename 's/_/ /g' name/of/directory/Dragonball_z*
If you stand in the directory where you wish to rename, and you want this to process all files, a simple * will do (no need to print out the path and the start of the filename).

If your structure is something like "$ANIME_DIR/anime_name", then you can just do */* (if you're in the $ANIME_DIR, that is), and it will work through it all. However, I do recommend that you run it with the -n flag first, as it shows what it will do, without actually renaming anything.

Code: Select all

rename -n 's/_/ /g' */*
This was written from the top of my head, so don't just copy paste it. x]
rpgmaker
Posts: 18
Joined: 01 May 2016, 17:06

Re: Replace underscores for spaces using CLI

Post by rpgmaker »

Kaffe wrote:As you're on Linux, just use the command "rename" instead.

Code: Select all

rename 's/_/ /g' name/of/directory/Dragonball_z*
I know but the reason why I'm using filebot for this is because the rename util isn't available on my NAS. I can debian-chroot it but I haven't gotten around to it yet.
Post Reply