# Comparing file names with different extensions

**URL:** <https://community.unix.com/t/comparing-file-names-with-different-extensions/368169>\
**Category:** Shell Programming and Scripting\
**Created:** [September 4, 2017, 12:47pm UTC](https://community.unix.com/t/comparing-file-names-with-different-extensions/368169 "2017-09-04T12:47:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![apenkov](https://community.unix.com/letter_avatar/apenkov/32/6_449c533f586939b6e5f246632a46421f.png) [@apenkov](https://community.unix.com/u/apenkov)\
**Post date:** [September 4, 2017, 12:47pm UTC](https://community.unix.com/t/comparing-file-names-with-different-extensions/368169/1 "2017-09-04T12:47:30Z")

</div>

Hello, I need some help. I have files in one and the same directory, but with different extensions, like this:

```nohighlight
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:

```nohighlight
file3.MISS

```

Thanks!

---

<div class="post-metadata">

**Author:** ![RudiC](https://community.unix.com/letter_avatar/rudic/32/6_449c533f586939b6e5f246632a46421f.png) [@RudiC](https://community.unix.com/u/RudiC)\
**Post date:** [September 4, 2017, 4:05pm UTC](https://community.unix.com/t/comparing-file-names-with-different-extensions/368169/2 "2017-09-04T16:05:02Z")

</div>

Not too clear a specification... Howsoever, try

```nohighlight
for FN in *.IN; do [-f ${FN/IN/OUT}] || echo ${FN/IN/MISS}; done
file3.MISS

```

---

<div class="post-metadata">

**Author:** ![jim\_mcnamara](https://community.unix.com/letter_avatar/jim_mcnamara/32/6_449c533f586939b6e5f246632a46421f.png) [@jim\_mcnamara](https://community.unix.com/u/jim_mcnamara)\
**Post date:** [September 4, 2017, 4:14pm UTC](https://community.unix.com/t/comparing-file-names-with-different-extensions/368169/3 "2017-09-04T16:14:48Z")

</div>

```nohighlight
ls -1 /path/to/files |
 awk '{arr[substr($1, 1, index($1,".")-1 )]++;} 
          END{for (i in arr) {if (arr== 1){
                print i ".MISS"
                }}}' 

```

---

<div class="post-metadata">

**Author:** ![Mysturji](https://community.unix.com/letter_avatar/mysturji/32/6_449c533f586939b6e5f246632a46421f.png) [@Mysturji](https://community.unix.com/u/Mysturji)\
**Post date:** [September 5, 2017, 6:36am UTC](https://community.unix.com/t/comparing-file-names-with-different-extensions/368169/4 "2017-09-05T06:36:49Z")

</div>

```nohighlight
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:

```nohighlight
for file in *.IN
do
   if [[! -e ${file%%IN}OUT]]; then
      echo ${file%%IN}MISS
   fi
done

```

(I wrote the first example on the fly;) )
