Paramteric Expansion in BASH

How do you convert a list of files like this `error.12345678.0.0.0.0.0.0.0.0.0.0.0.0.0′ to like this `error.12345678′ ?

The total number of `.0′ s are random. Total number of error.* files are random.

Here is how you can do it

for f in error.*; do x=$f; while [[ $x = *.0 ]]; do x=${x%.0}; done; mv $f $x; done

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s