首页 \ 问答 \ 在sed中使用一个命令的输出作为替换文本(Use output of one command as replacement text in sed)

在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
更新时间:2022-09-29 06:09

最满意答案

我最终通过跳过整个前端解决了这个问题,因为这主要是所有不道德的所有权所在,并且只是简单地调用我需要的功能。


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.
  • 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 ...
  • 我找到了答案。 系统递归深度存在问题。 在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 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)