本文共 571 字,大约阅读时间需要 1 分钟。
How to add a prefix at the beginning of each line in Bash script on ?
如何在上的Bash 脚本的每一行的开头添加前缀 ?
For example, assume we have a file a.txt:
例如,假设我们有一个文件a.txt:
line 1line 2
I want to have,
我希望有,
pre line 1pre line 2
You may use , the stream editor for filtering and transforming text:
您可以使用 (流编辑器)来过滤和转换文本:
sed -e 's/^/pre /'
For example,
例如,
$ echo "line 1line 2" | sed -e 's/^/pre /'pre line 1pre line 2
You may also do prefix adding to lines of certain patterns. But this is out of this question.
您也可以在某些模式的行上添加前缀。 但这是不可能的。
翻译自:
转载地址:http://tfowd.baihongyu.com/