I have two files and I want to generate a new file with the lines found in
file2 but not in
file1. The original files are not sorted.
Now, here is the tricky part. Some of the lines in the files follow the following formats:
./$ARTIST/$ALBUM/$N1 - $N2 - $TITLE.(flac|mp3) ./$ARTIST/$ALBUM/$N1 - $TITLE.(flac|mp3) ./$ARTIST/$ALBUM/$N1. $TITLE.(flac|mp3)
$N2 are numbers of 1-3 digit length, e.g.
$TITLE can be made up of any sequence of alphanumeric characters including . and - but not /.
I want lines ending with
mp3 to be considered a match if
$TITLE are the same and the corresponding line to be excluded.
./The BEATLES/white album/01. Revo-lution.flac ./123-123/234-234/01 - 02 - 3769.flac ./THE BEATLES/abbey road/cover.jpg
./The BEATLES/white album/01. Notinfile1.flac ./123-123/234-234/03. 3769.flac ./THE BEATLES/abbey road/cover.jpg
./The BEATLES/white album/01. Notinfile1.flac
I have thought about the problem and have come up with a solution but need someone to help me code it.
For each line of both files a key can be generated using the following method. Subsequent comparison of the keys between the files can be used to output the lines in
file2 whose keys do not match those in
Key generation as follows:
If line does not end with
mp3, key is the line itself.
Else, check for the first occurrence of
- after the last
. is the case, then key is
$TITLE is whatever comes after the dot.
- is the case, then count the number of dashes in the part of the line after the last
If one is found then key is
$TITLE is whatever comes after the dash.
If more than or equal to two dashes found, then check if what comes between the first and second dash is purely numbers and spaces. If it is, then
$TITLE is after the second dash. If it isn't, then
$TITLE is after the first dash.
Will someone please help me code this?