-4

I have two files with following contents

file 1:

9/09a-A5
9/09a-A18
9/09b- 2B
9/09a-A9
9/09b- 7
9/09a-A11
9/09a-A14
9/09c- 16
9/09b- 5
9/09b- 12
9/09a-A25
9/09a-A10Y
9/09a-A17Z
9/09a-A12Z
9/09b- 4Z
9/09a-A26Y
9/09a-A13
9/09a-A27
9/09a-A19
9/09a-A10
9/09a-A17Y
9/09a-A4
9/09a-A7
9/09a-A15
9/09b- 1
9/09a-A19Z
9/09a-A26
9/09a-A16
9/09a-A22Z
9/09a-A10Z
9/09a-A26Z
9/09a-A13Z
9/09b- 9
9/09b- 4

file 2

9/09b- 2
9/09b- 2A
9/09b- 2B
9/09b- 4Z
9/8B-13
9/9A-11
9/9A-13
9/9A-13Z
9/9A-14
9/9A-6
9/9A-8
9/9A-A13
9/9B-1
9/9B-10
9/9B-12
9/9B-3
9/9B-4
9/9B-5
9/9B-7
9/9B-9
9/9C-15
9/9C-16
9/9D-17

I want to take row 1 from file 1 and search for same name in file 2, if it is there then print. Please note that there are spaces and upper and lower cases to be ignored while searching. here result should be

9/09b- 2B
9/09b- 5
9/09c- 16
9/09b- 12
9/09b- 4Z
9/09a-A13
9/09b- 1
9/09b- 9
9/09b-
Rahul
  • 13,589

1 Answers1

-2
for i in `cat file1 | sed -e 's/ //g'`
do
    echo file1:${i},file2:`grep $i file2`
done

or something like that...

or maybe:

for i in `cat file1 | sed -e 's/ //g'`
do 
    for o in `cat file2 | sed -e 's/ //g'`
    do
        [[ $i == $o ]] && echo We have a match: $i $o
    done
done
Hugo
  • 1
  • It does not work as some name are having spaces in both the files and those values are ignored. e.g 9/09b -3 is same in file 2. – user183218 Aug 07 '16 at 15:18