[Gloucs] bash Q

Maximillian Murphy m at de-minimis.co.uk
Sun May 13 23:54:52 BST 2007


Am 13.05.2007 um 16:06 schrieb Glyn Davies:

> One for Dr Bash et al.
>
> I have some files in a directory. They have random names (usually  
> based on date) but all end in .00n (where n is a number i.e. .001, . 
> 002, etc)
>
> I have a script to rename the files based on their creation time.  
> That bit works fine. However, I want to maintain the suffix of the  
> original file. The problem is that some of the original files  
> contain '.'s in the non suffix part.
>
> So, for example:
>
> 03042006.001 will become 20060403.001
>
> The suffix is easily found with echo 03042006.001 | awk -F.  
> '{ print $2}'

The bash answer is the best, but for if ever you need to do it in awk  
you can by changing your script minimally:

echo 03042006.gag.001 | awk -F. '{ print $(NF)}'

In general, if you have a variable, say i=3, then $(i) is the same as  
$3 (in awk, would it were so in ksh!!).  NF is the number of fields  
in the current record.

Regards, Max




More information about the gloucs mailing list