bash reg expression to split many file names on _3charnumbers_
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
bash reg expression to split many file names on _3charnumbers_
friends,
I think what I need to do is split strings with a regular expression
where : _ and any 3 numbers underscore is my deliminator
I need to split a string ( a dir full of file names , thousands of mov files )
they all have the various forms of this
jug_WNYW_0000013_001_CommercialBlock7.mov
jug_WNYW_0000013_002_CommercialBlock7.mov
all the way to
jug_WNYW_0000013_099_CommercialBlock7.mov
and here are other examples
jug_WNYW_0000013_041_WeatherTwo.mov
jug_WLWT_0000099_022_reds.mov
jug_WLWT_0001234_001_reds.mov
jug_WCPO_0008994_007_shewalkedintothedoor.mov
b99456666_007_shetakesawall.mov
c9902345_003_chocolatepieisgood.mov
what I really wish i could do get get what ever is LEFT of the underscore 3 wide number underscore
goodStuff_NNN_
i wish for the good stuff
I tried a reg expression with
tapeName="$(cut -d'_[0-9]{3}_' -f1 <<<"$jug_1978-03-31_wlwt_AIR_005_SubheadsTeasers")"
i Thought the _[0-9]{3} would be
underscore and any 3 numbers and underscore
userx@slacurr.ent.org:~
$ fun=jug_WNYW_0000013_001_CommercialBlock7.mov
#furthest to the right
$ sofun=${fun##*[0-9]_}
$ echo $sofun
CommercialBlock7.mov
it *seems the mac (os 10.11) also does not take sed from standard in .... isn't that nice
I find that very hard to believe. But I wouldn't be caught dead using a mac, so I can't check.
Could be done with parameter substitution, but I always mess up complex globs. Does anyone know if/how you can include a (specific) repetition count in a glob in a substring removal like that ?.
I also agree the perl rename is best option as you can use regex to get the job done. But you'd better get it correct (for all cases).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.