0

I'm trying to do the following: list files or directories containing certain characters then from the last slash in the path search for particular characters and replace them with a -.

I built the following on regexpr but it does nothing with sed:

find . -name "*[<>:\\|?]*" | while read -r; do mv "${REPLY}" \
"`echo ${REPLY} | sed "s/([^/]+$)*([<>:\\|?])/-/g"`"; done

1 Answer 1

1

How about something cleaner like:

find ... |
while read -r f; do
    dir=$(dirname "$f")
    old_name=$(basename "$f")
    new_name=$(echo "$old_name" | tr '<>:\\|?' '-')
    mv "$dir/$old_name" "$dir/$new_name"
done

You must log in to answer this question.

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