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

Recommended Answers

All 2 Replies

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 developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.