Hi All,
I am very new to Shell scripting...
I got a requirement.
I will have few text files(data files) in a particular directory. they will be with .txt extension. With same name, but with a different extension control files also will be there. For example, Sample_20081001.txt is the data file, then Sample_20081001.ctl will be the control file.
Now if the ctl file exists, then only i have to move that particular txt file into another directory. Others i should not move. And the .txt and .ctl files will be multiple. This is my requirement.
Can anybody please give a solution?
Thank you very much.
Can you tell me wht x%% refers... As i am new to shell scripting, i am not able to understand the code snippet you have given...
Can you please explain how this works... So that i can tailor it according to my requirement....
#look for all the .ctl files
for each in $(ls -1 *.ctl)
do
#extract the filename without ctl extention and search for {filename}.txt
# if it is there, move to a different folder
[[ -f "${each%%.ctl}.txt" ]] && { mv ${x%%.ctl}.txt ./new_folder/ }
done