Need help with sed or awk and regular expressions

Michael Ault mikerault at yahoo.com
Sun Jul 3 15:43:56 UTC 2005


Ultimatly we want to automate this. Sometime in the
future there may be 2 files (_1, _2) per load.
However, that is several years in the future.

Thanks!

Mike

--- inode0 <inode0 at gmail.com> wrote:

> On 7/2/05, Michael Ault <mikerault at yahoo.com> wrote:
> > Excellent, so to pass in a list of file names to
> be
> > converted you would pipe the results of the ls
> command
> > through this? We have a list of about 100 files
> that
> > need to be renamed.
> 
> This makes me a little nervous, are we really really
> sure that all the
> shorter names will be unique after we chop things
> up? Here is how I
> would proceed from a bash shell directly ...
> 
> Make sure extglob is on:
> 
> $ shopt extglob
> extglob         on
> 
> If it is off run
> 
> $ shopt -s extglob
> 
> Here are some sample files in the current directory
> ...
> 
> $ ls
> 44.MR3M01J.AF_TBL_COL_1.2005-06-30.DAT 
> 44.MR3M01J.CF_TBL_COL_2.2005-06-30.DAT
> 44.MR3M01J.BF_TBL_COL_2.2005-06-30.DAT 
> 44.MR3M01J.DF_TBL_COL_1.2005-06-30.DAT
> 
> I like to echo dangerous things first and carefully
> check that
> everything looks right before actually running the
> command (good idea
> to back up the directory first to be safe too).
> 
> $ for f in *; do echo mv $f
> ${f//+(44.MR3M01J.|_[12]*[0-9])}; done
> mv 44.MR3M01J.AF_TBL_COL_1.2005-06-30.DAT
> AF_TBL_COL.DAT
> mv 44.MR3M01J.BF_TBL_COL_2.2005-06-30.DAT
> BF_TBL_COL.DAT
> mv 44.MR3M01J.CF_TBL_COL_2.2005-06-30.DAT
> CF_TBL_COL.DAT
> mv 44.MR3M01J.DF_TBL_COL_1.2005-06-30.DAT
> DF_TBL_COL.DAT
> 
> If you are satisfied that all the renames are
> correct, please
> especially check that each target is unique since if
> you have both
> 44.MR3M01J.AF_TBL_COL_1.2005-06-30.DAT and
> 44.MR3M01J.AF_TBL_COL_2.2005-06-30.DAT for instance
> there will be a
> problem, you can remove the echo from the last
> command to run it
> 
> $ for f in *; do mv $f
> ${f//+(44.MR3M01J.|_[12]*[0-9])}; done
> $ ls
> AF_TBL_COL.DAT  BF_TBL_COL.DAT  CF_TBL_COL.DAT 
> DF_TBL_COL.DAT
> 
> Hope that helps. Be careful. :)
> 
> John
> 
> _______________________________________________
> Redhat-install-list mailing list
> Redhat-install-list at redhat.com
>
https://www.redhat.com/mailman/listinfo/redhat-install-list
> To Unsubscribe Go To ABOVE URL or send a message to:
> redhat-install-list-request at redhat.com
> Subject: unsubscribe
> 


Michael R. Ault
Senior Consultant
Burleson Oracle Consulting
770-754-9057
www.ault.cc
www.remote-dba.com




More information about the Redhat-install-list mailing list