dslreports logo
site
 
    All Forums Hot Topics Gallery
spc

spacer




how-to block ads


Search Topic:
uniqs
1235
share rss forum feed


regexuser

@199.19.94.x

REGEX HOWTO's/Tutorials for BASH scripts/commands

Looking for HOWTO's, tutorials etc. for REGEX use with BASH scripts and commands. Specifically with find and mv

pseudeo code (NOT VALID!)
ie: find /Some.Directory.S[0-9][0-9]E[0-9][0-9].720p.*/i
 
and then mv $newepi (some existing directory structure)
 

I have tons of inbound files/directories I need to manipulate based on the name, and REGEX would be the perfect item.

Unfortunately REGEX and I don't agree. I manage to make the REGEX work on the source side by luck, trial, errors, etc..

I would like to fine tune e REGEX knowledge but what I find is aimed at people who seem to have developed and understand this already.

I am looking more for REGEX for Abject ReGEX HATERS AND DUMMIES!

The goal is to process directories into other directories based on the REGEX naming convention of the new directories.

Pointers to HOWTO/Tutorials as per the motto of "REGEX for Abject ReGEX HATERS AND DUMMIES!" would be great.

Thanks in advance.

PS: If it matters :

$ bash --version
GNU bash, version 4.2.24(1)-release (i686-pc-linux-gnu)
Copyright (C) 2011 Free Software Foundation, Inc.
 
$ uname -a
Linux (censored) 3.2.0-38-generic-pae #61-Ubuntu SMP Tue Feb 19 12:39:51 UTC 2013 i686 i686 i386 GNU/Linux
 
 

For Debian/*buntu KDE centric user and distro's, and I don't speak non Linux or have access to non Linux, hence why I am asking here. I don't want to get generic answers or one based on some other OS I have never used.

Thanks!

pablo
MVM
join:2003-06-23
kudos:1
Hi,

My approach is to always break down a problem to "bite size chunks", solve it and move to the next "chunk" I string them all together and hope not to "blow chunks" :)

Let's first try to ensure we "find" the files you want.

The following seemed to work in my wee little sandbox:

cd /the/top/level/directory/to/search
find . -type d -iname 'Some.Directory.S[0-9][0-9]E[0-9][0-9].720p.*'


Does it work for you? Does it find the directories you're interested?

FYI: "man find" provides oodles of goodies.

Cheers,
-pablo

--
openSUSE 12.2/KDE 4.x
ISP: TekSavvy Bonded DSL; backhauled via a 6KM wireless link
Assorted goodies: »pablo.blog.blueoakdb.com


Drunkula
Premium
join:2000-06-12
Denton, TX
Reviews:
·Verizon FiOS
reply to regexuser
I'm no regex master but just a suggestion... Wouldn't it be better to replace the [0-9][0-9] with [\d]{2} instead?

--
There are 10 types of people that understand binary numbers. Those that do - and those that do not...

garywk

join:2001-03-06
Clarkston, WA
reply to regexuser
Here's a link to a pretty thorough tutorial.

»www.regular-expressions.info/tutorial.html


RegexUser

@199.19.94.x
reply to pablo
said by pablo:
FYI: "man find" provides oodles of goodies.
man is what left the bad taste to start..these man pages all to often suffer "wirtten for those who already know how to use..." it reads like to repeat the oft stated cliché... "Reads like stereo instructions for the dead."

I'll review the other posts and see where it gets me. THANKS!

pablo
MVM
join:2003-06-23
kudos:1
said by RegexUser :

said by pablo:
FYI: "man find" provides oodles of goodies.
man is what left the bad taste to start..these man pages all to often suffer "wirtten for those who already know how to use..."

Hi,

One thought you may consider is to be the /someone/ to change the "man page" That's the spirit of Open Source: be the /someone/ to affect change.

Cheers,
-pablo
--
openSUSE 12.2/KDE 4.x
ISP: TekSavvy Bonded DSL; backhauled via a 6KM wireless link
Assorted goodies: »pablo.blog.blueoakdb.com


RegexUser

@199.19.94.x
said by pablo:
One thought you may consider is to be the /someone/ to change the "man page" That's the spirit of Open Source: be the /someone/ to affect change.

Wrong person for that. That will be done by someone else, not me.


Maxo
Your tax dollars at work.
Premium,VIP
join:2002-11-04
Tallahassee, FL
reply to garywk
said by garywk:

Here's a link to a pretty thorough tutorial.

»www.regular-expressions.info/tutorial.html

This is the site I use as a reference. Of course implementations can vary, but this site does a good job as both a tutorial and reference guide.


Maxo
Your tax dollars at work.
Premium,VIP
join:2002-11-04
Tallahassee, FL
reply to regexuser
I'd also like to give you a ++ for taking on learning regex. I don't think anyone goes in feeling confident, but once you get the basic hang of things, which took me a looong time, it is really powerful and useful in many situations.

pablo
MVM
join:2003-06-23
kudos:1
Hi,

RE's are quite powerful and once you get the general idea, they're very easy.

Cheers,
-pablo

dave
Premium,MVM
join:2000-05-04
not in ohio
kudos:8
Reviews:
·Verizon FiOS
reply to Drunkula
said by Drunkula:

I'm no regex master but just a suggestion... Wouldn't it be better to replace the [0-9][0-9] with [\d]{2} instead?

Better in what sense? Unless this is destined for a long life where it will be examined and modified by others, I think the rule of 'whatever works' applies here.

Besides (1), [0-9][0-9] is probably valid in practically any regular-expression parser anywhere, and [\d]{2} is much less universal.

Besides (2), [0-9][0-9] is certainly more obvious to the reader (which is why our writer came up with this form).

Don't sweat the small stuff.

dave
Premium,MVM
join:2000-05-04
not in ohio
kudos:8
Reviews:
·Verizon FiOS
reply to regexuser
Could you be more specific about your comprehension problem?

Basically a regular expression is a way to provide a template for matching strings (in your case, filenames).

The regexp syntax is, I think, largely secondary to the question of what the hell you're trying to do in the first place. If you want to match certain files, then you first have to figure out a rule that matches those names and those names only -- and that's the part that might require a little cunning. You have to be able to spot patterns like "first two characters are digits, next is a letter in the set PQRS, and then there is one or more other arbitrary characters".

Translating that to a regexp is largely a mechanical exercise, that gets easier the more you do it.

pablo
MVM
join:2003-06-23
kudos:1
reply to dave
I think the rule of "what's more obvious to the maintainer" (paraphrasing what you wrote should trump "whatever works"

Of course, if we're talking super critical, kernel code, then tune the hell out of it and document 2x more.

Cheers,
-pablo
--
openSUSE 12.2/KDE 4.x
ISP: TekSavvy Bonded DSL; backhauled via a 6KM wireless link
Assorted goodies: »pablo.blog.blueoakdb.com

dave
Premium,MVM
join:2000-05-04
not in ohio
kudos:8
Reviews:
·Verizon FiOS
Personally, I'm in favour of "the entire filter program needs to be expressed in one single pattern-match and in the shortest possible regexp", but I don't think that sort of attitude will help the OP

pablo
MVM
join:2003-06-23
kudos:1
Are you suggesting a nerd-a-thon where we try to take his expression and crunch it to the smallest possible RE? hah hah!

Just kidding!

-pablo
--
openSUSE 12.2/KDE 4.x
ISP: TekSavvy Bonded DSL; backhauled via a 6KM wireless link
Assorted goodies: »pablo.blog.blueoakdb.com


Drunkula
Premium
join:2000-06-12
Denton, TX
Reviews:
·Verizon FiOS
reply to dave
It's just a preference thing. Instead of reading "any single digit followed by any single digit" I read it as "any two digits". But I digress. That is not what the OP asked...
--
There are 10 types of people that understand binary numbers. Those that do - and those that do not...