Bash 如何在每行循环文本文件并在每行附加其他文本

Bash 如何在每行循环文本文件并在每行附加其他文本,bash,shell,Bash,Shell,如何循环文本文件中的每一行并附加其他文本在shell中换行 text.txt a b c 剧本 while read p; do echo $p done </Users/admin/Desktop/tutorial/text.txt 读取p时;做 回声$p 完成printf是你的朋友: while read p; do printf "<url>\n\t<loc>http://domain/%s</loc>\n\t<priority>

如何循环文本文件中的每一行并附加其他文本在shell中换行

text.txt

a
b
c
剧本

while read p; do
  echo $p
done </Users/admin/Desktop/tutorial/text.txt
读取p时
;做
回声$p

完成
printf
是你的朋友:

while read p; do
printf "<url>\n\t<loc>http://domain/%s</loc>\n\t<priority>0.9</priority>\n</url>\n" "$p"
done < /Users/admin/Desktop/tutorial/text.txt

<url>
   <loc>http://domain/a</loc>
   <priority>0.9</priority>
</url>
<url>
   <loc>http://domain/b</loc>
   <priority>0.9</priority>
</url>
<url>
   <loc>http://domain/c</loc>
   <priority>0.9</priority>
</url>
读取p时
;做
printf“\n\thttp://domain/%s\n\t0.9\n\n“$p”
完成
while read p; do
printf "<url>\n\t<loc>http://domain/%s</loc>\n\t<priority>0.9</priority>\n</url>\n" "$p"
done < /Users/admin/Desktop/tutorial/text.txt

<url>
   <loc>http://domain/a</loc>
   <priority>0.9</priority>
</url>
<url>
   <loc>http://domain/b</loc>
   <priority>0.9</priority>
</url>
<url>
   <loc>http://domain/c</loc>
   <priority>0.9</priority>
</url>