matching files with regular expressions

Posted by Javier on Stack Overflow See other posts from Stack Overflow or by Javier
Published on 2010-06-15T09:17:22Z Indexed on 2010/06/15 9:22 UTC
Read the original article Hit count: 372

Filed under:
|
|

Dear all,

I have an input file with a list of movies (Note that there might be some repeated entries):

American_beauty__1h56mn38s_
As_Good_As_It_Gets
As_Good_As_It_Gets
_DivX-ITA__Casablanca_M_CURTIZ_1942_Bogart-bergman_
Capote_EN_DVDRiP_XViD-GeT-AW
_DivX-ITA__Casablanca_M_CURTIZ_1942_Bogart-bergman_

I would to find the corresponding match (line number) from another reference file for each of the entries in the first file:

American beauty.(1h56mn38s)
As Good As It Gets
Capote.EN.DVDRiP.XViD-GeT-AW
[DivX-ITA] Casablanca(M.CURTIZ 1942 Bogart-bergman)
Quills (2000)(7.4) 

The desired output would be something like (Reference Movie + Line number from the Reference File):

American beauty.(1h56mn38s) 1
As Good As It Gets 2
As Good As It Gets 2
[DivX-ITA] Casablanca(M.CURTIZ 1942 Bogart-bergman) 4
Capote.EN.DVDRiP.XViD-GeT-AW 3
[DivX-ITA] Casablanca(M.CURTIZ 1942 Bogart-bergman) 4

Basically, the difference between the entries in both files is that some characters such as: blank spaces, parenthesis, points, etc. have been replaced by underscores.

Does anybody could shed some light on it?

Best wishes,

Javier

© Stack Overflow or respective owner

Related posts about bash

Related posts about awk