How to remove '/' from keys in a .yaml file if the '/' is the first character #1560
Answered
by
mikefarah
williamj20
asked this question in
Q&A
-
Hi, I have a bunch of paths in a .yaml file which start with '/'. For example: '/api/path'. I would like to remove all instances of these paths which start with '/', so that they become 'api/path'. How can I achieve this? |
Beta Was this translation helpful? Give feedback.
Answered by
mikefarah
Feb 20, 2023
Replies: 1 comment
-
You can use the sample file (next time please provide one) - /a/path
- something/else
output: - a/path
- something/else Explanation:
|
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
williamj20
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can use the
sub
operator (see https://mikefarah.gitbook.io/yq/operators/string-operators#sub-regex-replacement) like this:sample file (next time please provide one)
output:
Explanation:
.[]
will match all the elements in the array|=
will update each element, with respect to itselfsub("^/", "")
matches a leading/
and replaces it with an empty string