New answers tagged

1

I doubt that your sed command works on RedHat as the spacing in the regular expression wouldn't match in the example document that you are showing. Also, parsing or modifying a document written in a structured document format such as XML is at best hazardous with a line-oriented text editing tool like sed. The second issue is your use of the non-standard -i ...


0

Looks like this works: sed -i '/duper_service/!b;n;c\ \ \ \ app_version: 4.0.2' file.txt


0

sed seems a good candidate for this: sed -i '/^[[:space:]]*duper_service:/ { N; s/[^:]*$/ 4.0.2/ }' file.txt Explanation: when the "duper_service:" line is encountered, next line is appended and whatever ends that line, after the colon, ([^:]*$) is replaced with "4.0.2". The -i option changes the file in-place. It's a GNU sed extension.


0

I will not judge you about using sed on yaml file.. Everyone use what he wants to get things done. I had the same issue some time ago, and it seems that if you 'brace' your vars in the sed regex, the whole thing starts to works: $ cat $file version: '3' services: mongo: container_name: mongo image: mongo:3.4 volumes: - /home/mongo_files:...


3

You should not use sed to work with YAML files, or files written in any structured document format (YAML, JSON, XML, etc.) Instead, use a parser written for that document format. For YAML, there are two good tools written for the shell, both confusingly called yq. The yq from https://kislyuk.github.io/yq/ is an easy to use jq wrapper (and jq is a JSON ...


4

As usual, you really do not want to modify XML files using a line-oriented text editing tool. XML is not a newline-delimited document format. To update the /Component/apiVersion node's value in a single XML document, consider using xmlstarlet like so: xmlstarlet ed \ -N x='http://soap.sforce.com/2006/04/metadata' \ -u '/x:Component/x:apiVersion' -v '...


2

If your files are all as simple as you show, you can do: find force-app -type f -name "*-meta.xml" \ -exec sed -i '' -e 's|<apiVersion>[0-9]*[0-9.]*[0-9]*</apiVersion>|<apiVersion>52.0</apiVersion>|' {} \; Note that on Linux, that will give an error and you can use this instead: find force-app -type f -name "*-meta....


Top 50 recent answers are included