Need help with sed or awk and regular expressions

Carl Reynolds redhat-install-list at hyperbole-software.com
Sat Jul 2 02:19:32 UTC 2005


Michael Ault wrote:

>I need a sed or awk type command that will convert:
>
>44.MR3M01J.AF_TBL_COL_1.2005-06-30.DAT
>
>to AF_TBL_COL.DAT
>
>the 44.MR3M01J. is always the same, the "_1" could be
>both "_1" or "_2", the date varies by month end and
>the ".DAT" stays the same.
>
>  
>
Try
    sed -n -e 's/44.MR3M01J.\(.*\)_[12]\..*/\1.DAT/' input-file >
output-file

This will also do the same thing:
    sed -n -e 's/[0-9][0-9]\.[0-9A-Z]*\.\([^.]*\)_[12]\..*/\1.DAT/'
input-file > output-file
but will allow the prefix and the suffix of the input to change. Note
that it totally disregards the date in the input string so it can change
also.



Carl.






More information about the Redhat-install-list mailing list