Re: regex help

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Tim here.  There are a lot of flavors of regular expression, so you'd
have to pick the tool first and then craft the regex according to
that engine.  For bulk renaming, I'm partial to the perl "rename"
tool, which fortunately has the gold standard of regex, PCRE syntax.

So I'd test it with

   rename -n 's/(\b[[:alpha:]])\./$1/g' *.txt

and if the results look good, remove the "-n" dry-run flag and run it
again.

The regular expression captures (using the parens) any
single alphabetic character ("[[:alpha:]]"), and that letter must
stand alone (the "\b" enforces a word-boundary before that letter),
followed by a literal period ("\.") and replaces it with the letter
we captured (without the period).  The "g" flag instructs it to do
every instance it finds in the filename, not just the first one.

Hope this helps!

-Tim

On February  9, 2022, Linux for blind general discussion wrote:
> I want to create a regex that will look for single letters followed
> by a dot. This is for porpoises of file renaming. For example. J.
> S. Smith - Become an Evil Dictator- A Step by Step Guide.txt Arthur
> A. C. Johnson - How to Win Minions and Overthrow Governments.txt
> 
> The regex should look for and remove the dots. So the file names
> end up being: J S Smith - Become an Evil Dictator- A Step by Step
> Guide.txt Arthur A C Johnson - How to Win Minions and Overthrow
> Governments.txt
> 
> Is it possible to craft a regex to just find all single letters,
> followed by a dot? What file renamer is the best one to use for
> this? The one I currently use is brename
> https://github.com/shenwei356/brename but if there is a better
> tool, would love to know it. Thanks.
> 
> 
> _______________________________________________
> Blinux-list mailing list
> Blinux-list@xxxxxxxxxx
> https://listman.redhat.com/mailman/listinfo/blinux-list
> 

_______________________________________________
Blinux-list mailing list
Blinux-list@xxxxxxxxxx
https://listman.redhat.com/mailman/listinfo/blinux-list




[Index of Archives]     [Linux Speakup]     [Fedora]     [Linux Kernel]     [Yosemite News]     [Big List of Linux Books]