Computing.Net > Forums > Unix > Compare file names then move

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

Reply to Message Icon

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

Thank you.

ihsail




Sponsored Link
Ads by Google

Response Number 1
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

ihsail


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Compare file names then move

shell script for comparing file www.computing.net/answers/unix/shell-script-for-comparing-file-/7685.html

Read File name and pass to SQLoader www.computing.net/answers/unix/read-file-name-and-pass-to-sqloader/5543.html

Help - File Name Manipulation www.computing.net/answers/unix/help-file-name-manipulation/6465.html