Comparing file names with different extensions


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Comparing file names with different extensions
# 1  
Old 09-04-2017
Comparing file names with different extensions

Hello, I need some help. I have files in one and the same directory, but with different extensions, like this:
Code:
file1.IN
file2.IN
file3.IN
file1.OUT
file2.OUT

Apparently some files with OUT extension can be missing. So I want to compare *.IN and *.OUT, ignoring the extension and get result like:
Missing OUT files:
Code:
file3.MISS

Thanks!
# 2  
Old 09-04-2017
Not too clear a specification... Howsoever, try
Code:
for FN in *.IN; do [ -f ${FN/IN/OUT} ] || echo ${FN/IN/MISS}; done
file3.MISS


Last edited by RudiC; 09-06-2017 at 02:25 AM.. Reason: converted file "extensions" to upper case.
# 3  
Old 09-04-2017
Code:
ls -1 /path/to/files |
 awk '{arr[ substr($1, 1, index($1,".")-1 )]++;} 
          END{for (i in arr) {if (arr[i]== 1){
                print i ".MISS"
                }}}'

# 4  
Old 09-05-2017
Code:
for file in *.IN
do
   if [[ -e ${file%%IN}OUT ]]; then
      :
   else
      echo ${file%%IN}MISS
   fi
done

---------- Post updated at 11:36 ---------- Previous update was at 11:23 ----------

... or make it quicker/simpler with:
Code:
for file in *.IN
do
   if [[ ! -e ${file%%IN}OUT ]]; then
      echo ${file%%IN}MISS
   fi
done

(I wrote the first example on the flySmilie )
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. Shell Programming and Scripting

Comparing the pattern of the file names in 2 different directories

Hi, I have got a requirement for which i need your help. The following problem is required to get solved in PERL SCRIPT. Here is the requirement. There are 4 folders say SRC_DIR1, SRC_DIR2 and TGT_DIR_1,TGT_DIR_2 (Note: both path of SRC_DIR1 & SRC_DIR2 are different but both path of... (4 Replies)
Discussion started by: shadow_fawkes
4 Replies

3. Shell Programming and Scripting

**URGENT ** : Comparing the pattern of the file names in 2 different directories

Hi, I have got a requirement for which i need your help. The following problem is required to get solved in PERL SCRIPT. Here is the requirement. There are 4 folders say SRC_DIR1, SRC_DIR2 and TGT_DIR_1,TGT_DIR_2 (Note: both path of SRC_DIR1 & SRC_DIR2 are different but both path of... (1 Reply)
Discussion started by: shadow_fawkes
1 Replies

4. Shell Programming and Scripting

Comparing File Names

Hi All , I am new to UNIX. I have a requirement where user transfers 10-15 files into a directory "/upload". File name will be like T1234_H and T1234_D or R1234_H and R1234_D . The _H and _D files are associated to each other.They must always be together in the server. Once the files are... (2 Replies)
Discussion started by: Raviteja_B
2 Replies

5. Shell Programming and Scripting

Grepping file names, comparing them to a directory of files, and moving them into a new directory

got it figured out :) (1 Reply)
Discussion started by: sHockz
1 Replies

6. Shell Programming and Scripting

Comparing files names in directory over two servers

Hi folks I need to write a shell script to check whether source and the destination has the same files. The source and destination are over two servers and connecting through ssh. It should even compare the date i.e, the complete file name, date stamp and size should match. Should list out all the... (3 Replies)
Discussion started by: Olivia
3 Replies

7. Shell Programming and Scripting

Searching for file names in a directory while ignoring certain file names

Sun Solaris Unix Question Haven't been able to find any solution for this situation. Let's just say the file names listed below exist in a directory. I want the find command to find all files in this directory but at the same time I want to eliminate certain file names or files with certain... (2 Replies)
Discussion started by: 2reperry
2 Replies

8. Shell Programming and Scripting

Comparing subdirectory names

I am trying to reformat data from one private directory and reformat it and move it to a public one, but i only want to get directories that have not already been moved to the public directory. Here's what i'm working with Dir1 contains folders for each named with timestamp 20090320081302... (2 Replies)
Discussion started by: dabombace
2 Replies

9. UNIX for Dummies Questions & Answers

Comparing file names to text document

Hi All, I'm really new to Unix scripts and commands but i think i'm eventually getting the hang of some of it. I have a task which is to create some kind of script which compares the file names in a directory, with the associated file name in a .txt file. We send out some data and Unix has a... (1 Reply)
Discussion started by: gman
1 Replies

10. Shell Programming and Scripting

File name extensions

Hello people, I was wondering if anyone could help me? I want to produce a shell script that changes the filename extension on all matching file. E.G. change all files called ‘something.rtf' to ‘something.doc' by giving the command: Changex rtf doc *where ‘Changex' is the name of... (2 Replies)
Discussion started by: thurrock
2 Replies
Login or Register to Ask a Question