I need to rename all the files in the current directory,if it contains specific letters using shell programming.
For that I used
foreach file
if (`grep $2 $file`) then
mv "$file" newname;
in $2 the specific characters are stored.
How should I modify this code?
Are there any simple way to do that?
I am using cygwin in windows xp

You need to give us exactly what you are doing. Your expected input, expected output.

The code as written will trash every file it works on except that last one, ie. dozens of files may become newname. How do you want the new name to be?

Thanks for your response.


The program should rename all the files that contain a specific word (eg:fact).

The Input;

If the directory contains file name such as
prg1fact-num.txt , prg1order-num.txt, prg2fact-num.txt, ...

The output should be
prg001fact-num.txt,prg002fact-num.txt ... like .

Will it be enough ?Or else I will send the source code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.