[ale] help with sed and regex

Scott Plante splante at insightsys.com
Tue Jul 26 17:40:55 EDT 2016


The rename command is the best solution, but if you don't have it you could do the same thing this way: 


for file in * 
do 
mv "$file" "${file:0:2}_${file:2}" 
done 

I tend to go to the "for file in" solution. I guess I never got in the habit of using rename. 


By the way, if you wanted to get only the directories that began with two lowercase letters followed by an uppercase letter (and exclude other stuff), you could use this in place of the * in either rename... or for file in...: 


[[:lower:]][[:lower:]][[:upper:]]* 


Scott 

----- Original Message -----

From: "DJ-Pfulio" <djpfulio at jdpfu.com> 
To: "Atlanta Linux Enthusiasts" <ale at ale.org> 
Sent: Tuesday, July 26, 2016 12:11:25 PM 
Subject: Re: [ale] help with sed and regex 

How's this? 

$ rename 's/^(.{1,2})/$1_/g' * 


On 07/26/2016 11:33 AM, Chuck Payne wrote: 
> Leam, 
> 
> Your example works, thanks. 
> 
> What I had was 
> 
> flSunshine 
> flHeat 
> flBeaches 
> 
> So yes I was trying to get 
> 
> fl_Sunshine 
> fl_heat 
> fl_Beaches 
> 
> On Tue, Jul 26, 2016 at 11:03 AM, DJ-Pfulio <djpfulio at jdpfu.com> wrote: 
>> I'd use 'rename' ... please post before and after examples. Also, what 
>> character set is this? Anything funny about the locale? UTF8, UTF16, UTF32 or 
>> something else? Perl regex handles these things, but you have to tell it correctly. 
>> 
>> On 07/26/2016 10:43 AM, Chuck Payne wrote: 
>>> Guys, 
>>> 
>>> I am still weak on regex. So I have a question. I got a list of 
>>> directories that I need to add _ too. It should be as the first two 
>>> character are lower for the state and then the Client name is a Upper 
>>> Case character. What is the best way to do that? 


_______________________________________________ 
Ale mailing list 
Ale at ale.org 
http://mail.ale.org/mailman/listinfo/ale 
See JOBS, ANNOUNCE and SCHOOLS lists at 
http://mail.ale.org/mailman/listinfo 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.ale.org/pipermail/ale/attachments/20160726/13a65eef/attachment.html>


More information about the Ale mailing list