Using ? with sed

The equivalent to x? is \(x\|\). However, many versions of sed support an option to enable “extended regular expressions” which includes ?. In GNU sed the flag is -r. Note that this also changes unescaped parens to do grouping. eg: echo ‘file_1.gz’|sed -n -r ‘s/.*_(.*)(\.gz)?/\1/p’ Actually, there’s another bug in your regex which is that … Read more

How to add directory recursively on git safe.directory?

From Git 2.36, you can also add * representing ‘all’ to the safe.directory. It’s not recursive as you asked, but it may help depending upon your situation i.e. git config –global –add safe.directory “*” See https://github.blog/2022-04-18-highlights-from-git-2-36/ and search for safe.directory. EDIT: As suggested by zcoop98, we should add double quotes around ‘*’.

Makefile `echo -n’ not working

The problem comes from the unfortunate interaction of two facts. First, make has two modes of operations depending on the complexity of the recipe to be run: If the command is easy, make will directly run the recipe with its builtin commands. This is what happens in your b case. If the command is complex, … Read more

Accessing a JSON object in Bash – associative array / list / another model

If you want key and value, and based on How do i convert a json object to key=value format in JQ, you can do: $ jq -r “to_entries|map(\”\(.key)=\(.value|tostring)\”)|.[]” file SALUTATION=Hello world SOMETHING=bla bla bla Mr. Freeman In a more general way, you can store the values into an array myarray[key] = value like this, just … Read more