This is a resend from a reply to a thread titled "sed or awk or ?"

There are few ways to do this, but here is one.  It is not particularly  
elegant; just a brute force way of doing it.  

But it does have the advantage of letting you test whether and how it will 
work by uncommenting the "print" statement and commenting out the "system".  
You can see if running the program does what you really want it to do and 
make changes before you go mucking about with the real mv command.

In this case person asking for help wanted to rename files named 
"process....." to "adi.....".  

Trying this out will introduce you to gawk and regular expressions.  Really 
cool stuff.

I'm pretty sure you could do this directly in bash, but I'm not particularly 
strong there.

/Pen

------------------------------------------
Create the following awk file named, say, "doit.awk" using your favorite 
editor.   Do this in, say, your home directory.

        {
          if (/^processed/)
            {
            new = $1
            gsub(/^processed/, "adi", new)
            syscmd = "mv " $1 " " $new
           # print syscmd
            system(syscmd)
            }
        }

In the directory that you want to change the filenames, execute the command

        ls -1 > myfiles

Now do the following command

        gawk -f ~/doit.awk myfiles


Want to buy your Pack or Services from MandrakeSoft? 
Go to http://www.mandrakestore.com

Reply via email to