Compare file names


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Compare file names
# 1  
Old 01-29-2007
Compare file names

Hi everyone,

How to compare between two filenames, in case the current filename is the same as the last one an alarm to be sent, in case the current filename is different from the last filename, no alarm to be sent.

Is there a way to do this?

Thanks in advance.
# 2  
Old 01-29-2007
Do you want compare size of two files or contents(text) ?
# 3  
Old 01-29-2007
No, i want to comapre to compare the name of the two files.
# 4  
Old 01-31-2007
Gurus,

I am also having the same questions. I want to compare only filenames (not content, size etc.). If names are not equal, then I want to quit the programm, if equal than I want to proceed. How can I check this? Thanks!
# 5  
Old 01-31-2007
#! /bin/bash

echo -e "Enter the first file name \n"
read file1

echo -e "Enter the second file name \n"
read file2

if [[ $file1 = $file2 ]]
then
echo -e "Both are equal \n"
else
echo -e "Both files are different \n"
fi

Copy this into a file, and execute the script.
This will work. But am sure, will have more effective ways of doing the same.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Compare Only "File Names" in 2 Files with file lists having different directory structure

I have a tar arcive arch_all.tar.gz and 4 batched tar archive . These batches are supposed to have all the files form arch1.all.tar.gz arch1_batch1.tar.gz arch1_batch2.tar.gz arch1_batch3.tar.gz arch1_batch4.tar.gz my issue is that the directory structure in "arch_all.tar.gz" is... (6 Replies)
Discussion started by: sumang24
6 Replies

2. Shell Programming and Scripting

Compare files with different names in different directories

Hi, I have a requirement to compare files in different directories with different names. The files have a datestamp in their name (It might not be a sequential datetimestamp). This is for Redhat Linux. I have more than 5 directories and more than 10 file in each directory to be compared. ... (4 Replies)
Discussion started by: GosarJunk
4 Replies

3. Shell Programming and Scripting

Exclude certain file names while selectingData files coming in different names in a file name called

Data files coming in different names in a file name called process.txt. 1. shipments_yyyymmdd.gz 2 Order_yyyymmdd.gz 3. Invoice_yyyymmdd.gz 4. globalorder_yyyymmdd.gz The process needs to discard all the below files and only process two of the 4 file names available ... (1 Reply)
Discussion started by: dsravanam
1 Replies

4. Shell Programming and Scripting

Compare two files and get only missing names

I need to compare two files (oldfile1 & newfile). Need to ignore the values which are present in both files. At the same time, i need to get only records in new file. Tried using Join -v1 -v2 oldfile1 newfile (suspect it has not worked as expected). could anyone of you please help me here. (5 Replies)
Discussion started by: Selva_2507
5 Replies

5. Shell Programming and Scripting

Compare file names on directory

Dears, Would you please help on following bash script: I want to get the most recent file named alfaYYYYMMDD.gz in one directory: for example: in directory /tmp/ ls -ltr alfa20130715.gz holding.gz alfa20130705.gz sart.txt merge.txt.gz alfa20130802.gz my result shoud be... (1 Reply)
Discussion started by: maxsub
1 Replies

6. Shell Programming and Scripting

Check for particular files and compare the file names

Hi, Below are the 2 files in directory /tmp: masterCSF242323.img indexCSF242323.img 1) I want to compare if both the number (242323) are same in both the files. If they are same print - Files matching, else print files do not match. 2) Also if only index file is present in that... (7 Replies)
Discussion started by: apatil65
7 Replies

7. UNIX for Dummies Questions & Answers

Compare the file names from a file to a directory

Hi, I have to acheive the below logic in the script. I have a file which has many columns and one of them is "File Names" and there will be only one such column name. Eg., cat File1 Number of files:10 File Names: ABC, DEF, RTY,URE .... ... ... The column will contain the... (3 Replies)
Discussion started by: Vijay81
3 Replies

8. UNIX for Dummies Questions & Answers

how to compare names of files?

hi, can somebody tell me how to compare names of files? the situation is I have 2 files file1 and file2 and I want to figure out which file has the biggest ending, in this case file2 is. thank you (3 Replies)
Discussion started by: s3270226
3 Replies

9. Shell Programming and Scripting

Compare file names and select correct elements to include in "for each loop"

Hi everyone, I`ll try to be most clear I can explaining my help request. I have 2 folders Folder A-->This folder receives files through FTP constantly Folder B-->The files from Folder A are unzipped and then processed in Folder B Sometimes Folder A doesn`t contain all... (2 Replies)
Discussion started by: cgkmal
2 Replies

10. Shell Programming and Scripting

Compare File Names in Different Directories...

I do not know much about shell scripting and need to create a script and I am at a loss. If someone can help me, that would be great!! I have two directories: /dir1 /dir2 I need to get the sequence number which is part of the filename in /dir1 and delete all files in /dir2 that are... (4 Replies)
Discussion started by: stky13
4 Replies
Login or Register to Ask a Question