【发布时间】:2016-01-22 14:45:16
【问题描述】:
我有一个名为“namelist.txt”的输入文件,其中包含电子邮件地址:
user1@domain.com
user2@domain.com
user3@domain.com
我正在尝试从此输入文件中读取地址并将它们的值插入到输出文件 (newfile.txt) 中,该文件应为:
user "user1@domain.com" with pass"pass" is "user1@domain.com" here
user "user2@domain.com" with pass"pass" is "user2@domain.com" here
user "user3@domain.com" with pass"pass" is "user3@domain.com" here
我最接近的是使用 awk:
awk '{print "user $0 there with pass"pass" is user $0 here"}' < namelist.txt > newfile.txt
然而,这会打印以下内容:
user $0 there with pass is user $0 here
user $0 there with pass is user $0 here
user $0 there with pass is user $0 here
这不会打印变量值或“通过”值。
我不知道我哪里错了,或者我是否在正确的轨道上,所以任何建议和/或指针都将不胜感激。
编辑:
使用:
awk '{print "user \""$0"\" there with pass \"pass\" is user \""$0"\" here}' file
在 Ubuntu (14.04.2 LTS) 上产生以下输出:
" 这里的通行证 "pass" 是用户 "user1@domain.com
“通过“pass”的here是用户“user2@domain.com
" 通行证 "pass" 的这里是用户 "user3@domain.com
上述代码在 UNIX 终端中运行良好,但在 Ubuntu 和 Raspberry Pi 中却不行。
我很困惑为什么发行版之间存在差异。
【问题讨论】:
标签: bash awk substitution