I'm new to bash scripting, and I would like to cut a string given a specific pattern. For example with the string /user/patch.403.json I would like to get and store in a variable /user only. How can I do this with one line of code?
This can be done in many different ways. It would be good if you indicate what is your final goal or, at least, what is the idea underlying: the first block? everything but the last two? ...
Another example with this pattern /user/cards/1212/make_default/put.200.json, I would like to get /user/cards/1212/make_default. My goal is to only get the beginning of the string eliminating /put.200.json with basic commands like cut or sed.
Is this about directories or text? If you got a relative path, say foo.txt, would you want the empty string or .? This looks to me like a case for dirname.
/user/cards/1212/make_default/put.200.json, I would like to get/user/cards/1212/make_default. My goal is to only get the beginning of the string eliminating/put.200.jsonwith basic commands like cut or sed.foo.txt, would you want the empty string or.? This looks to me like a case fordirname.