I have a list of directories starting from /root. Eg
random text /root/dir1/files random end
delete me /root/dir1/files/2dir I am waste
/root/examples/source alalalala
/root/example/header some other text
I want to use sed to take from every line the directory and remove everything else. My final output must be
/root/dir1/files
/root/dir1/files/2dir
/root/examples/source
/root/example/header
How can I do it? (extract everything starting from /root… until the end of the path)
YET ANOTHER EDIT: Seems that my initial evaluation of the question did not really read it as closely as it should have. Thanks to the commentary below, I’ve learned a few tricks, and can clear up this answer.
First, tylerl has shown a command that should work for this in sed in this answer. Neat trick, though I’ll probably stick to awk for this.
My own solution did not take into account the first couple of lines given in the description. ghostdog74 gives a solution that might work here.
Take a look at the above linked solutions.