在sed中使用一个命令的输出作为替换文本(Use output of one command as replacement text in sed)
我有一个.env文件,有一堆键值对,如下所示:
NAME=John Doe CITY=Timbuctoo CSS=<some value> PORT=3000
这是我尝试以编程方式更改的第三行。 是一个动态生成的md5散列,每次运行该命令时,都需要用新的散列代替。 这就是我生成哈希的方式:
$ date +%s | md5sum | cut -d' ' -f 1
我希望在使用sed时使用上述命令的输出作为替换文本。 但无法弄清楚如何使其工作。 以下是我迄今为止所完成的解决方案:
$ date +%s | md5sum | cut -d' ' -f 1 | sed -i.bak 's/^\(CSS=\).*/replacement/' ~/nano/.env
什么应该代替“替换”来确保原始值被
cut
返回的值所取代?I have a .env file with a bunch of key-value pairs like so:
NAME=John Doe CITY=Timbuctoo CSS=<some value> PORT=3000
It is the third line I'm trying to change programmatically. is a dynamically-generated md5 hash and each time I run the command, it needs to be replaced by a new hash. This is how I'm generating the hash:
$ date +%s | md5sum | cut -d' ' -f 1
And I wish to use the output of the above command as the replacement text when using sed. But can't figure out how to make it work. The following is the solution I have so far which is far from complete:
$ date +%s | md5sum | cut -d' ' -f 1 | sed -i.bak 's/^\(CSS=\).*/replacement/' ~/nano/.env
What should put in place of "replacement" to ensure the original value gets replaced by the value returned by
cut
?
原文:https://stackoverflow.com/questions/45484115
最满意答案
我最终通过跳过整个前端解决了这个问题,因为这主要是所有不道德的所有权所在,并且只是简单地调用我需要的功能。
I eventually solved this by skipping the entire Frontend, as that's mostly where all of the dodgy ownership lies, and simply calling the functions I need myself.
相关问答
更多-
我联系了支持人员,他们告诉我,我需要的东西不能完成。 I contacted the support and they tell me that what I need can't be done.
-
安装clang的问题(Issue in installing clang)[2022-08-07]
svn co http://llvm.org/svn/llvm-project/llvm/branches/release_31/ llvm31 cd llvm31 cd tools svn co http://llvm.org/svn/llvm-project/cfe/branches/release_31/ clang cd .. ./configure --enable-optimized --disable-doxygen --prefix=~/llvm31 make make install ... -
我相信你只需要设置CORS。 我通常使用barryvdh / laravel-cors包来做这件事 ,这使得它很容易安装。 I believe you just have to setup CORS. I usually do this up using the barryvdh/laravel-cors package which makes it very easy to setup.
-
我最终通过跳过整个前端解决了这个问题,因为这主要是所有不道德的所有权所在,并且只是简单地调用我需要的功能。 I eventually solved this by skipping the entire Frontend, as that's mostly where all of the dodgy ownership lies, and simply calling the functions I need myself.
-
有几个缩小匹配器形成其他匹配器的逻辑组合: anyOf就像“或”, allOf可以实现“和”, unless像“不”。 你的例子可能看起来像 functionDecl( anyOf( hasName("a"), hasName("b") )) There are several narrowing matchers that form logical combinations of other matchers: anyOf is like "or", allOf can implem ...
-
在某些输入文件上运行自定义clang前端工具时出现异常(Exception during running custom clang Frontend tool on some input files)[2022-03-20]
我找到了答案。 系统递归深度存在问题。 在Windows中,默认的递归深度限制是512.所以在提到的测试用例的情况下,即使在达到递归限制之前,堆栈也会发生溢出。 因此将递归深度限制降低到27可以避免堆栈溢出异常。 模板深度也是类似的情况。 I found the answer. There is problem with system recursion depth. On Windows default recursion depth limit is 512. So in the case of tes ... -
将域范围的权限委派给服务帐户就可以了。 我添加了以下范围: https://www.googleapis.com/auth/drive https://docs.google.com/feeds https://spreadsheets.google.com/feeds 确保在中定义这些范围 List
在代码中创建GoogleCredential时。 Delegating the domain-wide authority to the service account did the ... -
我在WebApiConfig类中添加了低于本地日期格式的设置。这将告诉web api json格式化器转换为本地时区。 var jsonFormatter = config.Formatters.JsonFormatter; jsonFormatter.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Local; 因此我不需要明确的GMT客户端操纵。 I have added below local date format se ...
-
这里的问题是你一直在使用错误的功能createDiagnostics。 createDiagnostics有两种形式 : void createDiagnostics(DiagnosticConsumer *Client = 0, bool ShouldOwnClient = true); static IntrusiveRefCntPtr
createDiagnostics(DiagnosticOptions *Opts, ... -
我相信我弄明白了这个问题。 在调用编译器实例上的许多方法之前,应始终在编译器实例上调用setInvocation ,因为它实际上只是代理调用。 在创建CompilerInvocation对象之后,我将setInvocation调用移到了右边,现在可以正常工作了。 I believe I figured out the problem. You should always call setInvocation on the compiler instance before calling a lot of t ...