linux - 在这种情况下如何使用 shell、bash 或 sed 命令

标签 linux bash shell awk sed

我有这个文件

name1
name2
name3

以及如何实现这个结果:

first
user:name1
end

first
user:name2
end

first
user:name3
end

我可以使用 sed 's#^#user:#' 来实现

user:name1
user:name2
user:name3

但仍未完成工作。任何人都可以帮助我。谢谢

最佳答案

要添加纯 bash 版本:

while read line; do echo -e "first\nuser:$line\nend\n"; done < names.txt

关于linux - 在这种情况下如何使用 shell、bash 或 sed 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25189094/

相关文章:

arrays - 巴什脚本。如何在 bash 脚本中编码 if (array=nothing) then echo "no element in array"

linux - 如何使用linux命令删除文件中字符串中的特殊字符

linux - 打印重复条目的行号

bash - 我怎样才能在 bash 中找到 "try to do something and then detect if it fails"?

linux - 在 printf 中使用颜色

c# - 如何获取通过 ADB 使用的当前键盘(当前 IME)

c - 为什么popen不和mpg123通信?

c++ - 如何使用 QProcess 运行 vim 终端

bash - 用****屏蔽输出卡号

linux - Tcpdump 命令 - Linux - Unix