String split and extract the last field in bash

Would you please try the following:

while IFS=, read -r f1 _; do    # set field separator to ",", assigns f1 to the 1st field and _ to the rest
    dna=${f1##*-}               # removes everything before the rightmost "-" from "$f1"
    echo "$dna"
done < "$FILENAME"

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top