1

I have csv file (products.csv) with product numbers

$ cat products.csv | head -3
2.20
2.21
2.22

in another directory I have thousands of product images in subdirectories.

I need to locate product images based on product number from products.csv file.

I have written a simple bash script to locate them:

#!/bin/sh

PRODUCTS_FOLDER="products";
PRODUCTS="products.csv";

for x in `cat $PRODUCTS`;
do
    FILE=`find $PRODUCTS_FOLDER -follow -iname "$x*"`;
    if [ -n "$FILE" ]; then
            echo "Product $x found:";
            echo "--> $FILE <--";
    else
            echo "Product $x not found";
    fi
    echo "-----------------------------------";
done

but it is not doing exactly what i need. In results i can find following:

-----------------------------------
Product 14.144 found:
--> products/Buchzeichen/14.144_Interlaken_sortiert.jpg
products/Motive/14.1448.jpg
products/Motive/14.1445.jpg
products/Motive/14.1449.jpg
products/Motive/14.1446.jpg <--
-----------------------------------

Correct result should contain only pictures with that number (14.444) without 14.1448, 14.1445, 14.1449, 14.1446

What regular exp should i use in find to get expected result? Or maybe, there is another way to solve it?

Your ideas or suggestions are highly appreciated

1 Answer 1

1

The following regular expression should work:

-regex ".*/$x[^0-9].*"

It contains the number right after the slash followed by a non-number.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .