Aaron wrote:
You can use bash replacement feature:

# A="Hello This is a test"

# echo $A
Hello This is a test

# echo ${A// /}
HelloThisisatest

A simple for loop and mv should handle it, example:

for i in *; do mv "$i"  "${i// /}"; done

If you have lots files in a dir, it could pose a problem, using find and -exec can help with that.
or ls *.txt or find I guess.


I will check out the bash replacement feature before I try this so I
understand what I am doing. History has proven the danger of blindly
copying a script without knowing what I am doing. (my linux history that
is )

The syntax is:

${var_name/search/replace}
${var_name//search/replace}

Note that the 2nd one 2 backslashes after var_name. The former replaces
only the 1st occurrence, while the latter replaces all.

You can use this method to handle some quick search and replace. Here's
another example:

Let's create some files to simulate a test scenario:

$ for i in `seq 20`; do touch backup$i.log; done
$ ls

backup10.log  backup14.log  backup18.log  backup2.log  backup6.log
backup11.log  backup15.log  backup19.log  backup3.log  backup7.log
backup12.log  backup16.log  backup1.log   backup4.log  backup8.log
backup13.log  backup17.log  backup20.log  backup5.log  backup9.log


Note the sort order. Assuming you want all of them to be in the format of backupXX.log

$ for i in backup?.log; do mv $i ${i/up/up0}; done
$ ls
backup01.log  backup05.log  backup09.log  backup13.log  backup17.log
backup02.log  backup06.log  backup10.log  backup14.log  backup18.log
backup03.log  backup07.log  backup11.log  backup15.log  backup19.log
backup04.log  backup08.log  backup12.log  backup16.log  backup20.log

HTH
--
Meir Kriheli
http://mksoft.co.il

=================================================================
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]



Reply via email to