Hello All!
Thanks for taking time out and helping.
My issue is, I have two files that have file names in it. Now, i need to go through each line of both the files and when the file names are different, i need to rename the file. Below is the example:
File1</
fil1ename1.txt
filename2,txt
Afilename3.txt
/>
File2</
filename1.txt
filename2.txt
filename3.txt
/>
Expected outcome:
rename filename3.txt in file2 to be Afilename3.txt.
I have tried many ways but its just going in infinite loop.
while
read newfile &&
read oldfile <&3
do
if [ "$oldfile" != "$newfile" ]; then
if [ -f "$oldfile" ]; then
echo mv -- "$oldfile" "$newfile"
fi
fi
done < file1 3<file2
Remove echo when you are done modifying and testing the code.
We can push the (implicit) loop down into a standard command and feed it with pairs of strings from the two files. So the core of this solution is paste -> xargs , the remainder of the demonstration script is setup and reporting: