Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.
Compare file names then move
Name: ihsail Date: December 22, 2005 at 08:30:06 Pacific OS: Unix CPU/Ram: 2GH
Comment:
Pleaser help...
Compare file names then move to new directory:
How do I compare the files in different directories to see if they are the same? I need to move the new files to another directory if the files have the same names. /full/path/directory/old/file_mmddyyyy.txt /full/path/directory/new/file_mmddyyyy.txt
If new files have the same names then move them (file_*.txt) from /full/path/directory/new to /full/path/directory/archive
Name: ghostdog Date: December 22, 2005 at 23:54:52 Pacific
Reply:
I assume you only want to compare filenames whether they are the same and then move them to another directory...
you could use a "for loop" , iterate over the files in /full/path/directory/old,
for i in /full/path/directory/old/* do if [ -e /full/path/directory/new/$i ];then # the if condition checks for file # exist, #move to archive done
The above is not the actual working code. It's just an idea for you.
0
Response Number 2
Name: ihsail Date: December 29, 2005 at 06:56:30 Pacific
Reply:
Here's the exact way to do the filename comparison between two directories:
cd /usr/home/data_files/archive ls - l *.dat > all_archive_files.txt archive_list=/usr/home/data_files/archive/all_archive_files.txt
for archive_file in `cat $archive_list` do echo $archive_file cd /usr/home/data_files/
if [ -f $archive_file ]; then echo "This filename [$archive_file] exists" mv $archive_file /usr/home/data_files/existing_files else echo "The filename [$archive_file] does not exist" fi done
Summary: Hi, I have a complex shell scripting requirement. 1. I need to fetch last 7 days archived log files by querying database. 2.Then I have to compare the file names i got from querying oracle table with...
Summary: I need a little help with a Script. I need to read a filename from a directorty based on a specific format. I will be looking for the file in a directory that will have a file added to it each month. ...
Summary: Thank you'll for all the response, and sorry not been clear about my request. The version control files within the directory appear as : abc{1}.txt abc{2}.txt abc{3}.txt . . so on As part of my migra...