Bash:替换管道标准输入中的子字符串 [英] Bash: replacing a substring in pipe stdin

查看:75
本文介绍了Bash:替换管道标准输入中的子字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试用新的子字符串替换stdin中的某个子字符串.在通过cat读取多个文件之后,我必须从管道中获取标准输入.然后,我想将更改后的字符串向前推送到管道.

I try to replace a certain substring from the stdin with a new substring. I have to get the stdin from the pipe, after reading several files by cat. Then I want to push the changed string forward to the pipe.

这是我要做的事情:

cat file1 file2 | echo ${#(cat)/@path_to_file/'path//to//file'} | ... | ... | ... | ...

我尝试用替换子字符串'path/to/file'替换子字符串@path_to_file(周围的引号是替换子字符串的一部分).

I try to replace the substring @path_to_file with the replacement substring 'path/to/file' (the surrounding quotes are part of the replacement substring).

但是bash给我一个错误消息:bad substitution

However bash gives me an error message: bad substitution

有什么主意我能做到这一点吗?

Any ideas how I could accomplish this?

推荐答案

您可以使用sed命令.

You can use the command sed.

cat file1 file2 | sed -e 's/@path_to_file/path/to/file/' ...

这篇关于Bash:替换管道标准输入中的子字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆