Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

renaming multiple files using regex and awk under Unix

Status
Not open for further replies.

erixire

Technical User
Jun 4, 2002
72
CA
Hi,

I want to use this simple awk script to rename some files in a directory:

awk '{gsub (\4+\, "_"); print}'

which replace every group of character "4" with a single underscore "_". So, for example:

toto4444.txt become toto_.txt

But I don't know how to combine this to use in a shell to do something like this:

mv *.* `the result of the awk expression`

Is it possible? Maybe not!
Thanks for the help
 
for all in `ls $DIR/$pat`
do
allnew=`echo $all | awk ' {gsub(/4+/,"",$0) '`
mv $DIR/$all $DIR/$allnew
echo "Renamed $all to $allnew."
done

To test comment out the fourth line.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top