1

The find command gives me output like

a/b/1.xml
a/1.xml
c/d/fd/fg/2.xml

I need to write a Bash command to be able to store only data after last / in a path.

doing find . -name "*.xml" >>mayflies.txt gives me the full path and stores it, but I need just the .xml part to store.

How can I do that? I was trying options like cut, but then, due to variable pattern, I got lost on how to make it work.

2 Answers 2

1

You can combine cut with rev to obtain what you want:

find . -name "*.xml" | rev | cut -d'/' -f1 | rev >> mayflies.txt
Sign up to request clarification or add additional context in comments.

Comments

0

Try this:

find . -name '*.xml' -exec basename '{}' \;

instead of just printing the result, it executes unix command basename to print only file name of what was found.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.