Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

5
  • Thanks for explaining your answer in a very detailed manner. My initial question was a bit more complicated. Is there any way we can generalize the answer where the subdirectory can be subsetted without the assumption of position?. Forex, Without the assumption of the 5th element. I had to edited the question earlier to reduce the complexity. Commented Sep 15, 2021 at 2:01
  • sure, you can use a regex to match and extract anything. the difficulty is in crafting the regex so that it matches exactly what you want and only what you want. You haven't provided any details on exactly what pattern you want to match. Without such details, your question is too broad to answer but I"ll guess ZRT[^/]+_[^/]+ to match anything beginning with ZRT and containing an underscore followed by some more characters. To extract that with sed: sed -E 's:.*/(ZRT[^/]+_[^/]+).*:\1:' Commented Sep 15, 2021 at 2:39
  • The broader question is off-topic here (because it's effectively asking for learning materials) but can be answered with "teach yourself regular expressions". Regular-Expressions.info is a good site to help with that. Commented Sep 15, 2021 at 2:42
  • This is a great resource. Commented Sep 15, 2021 at 3:47
  • I just realized that this is a better solution compared to any other as it works well in my case. Accepting this as my answer. Commented Sep 16, 2021 at 17:38