[英]Bash: Echo file contents precedes with counter
我正在寻找一个读取文件内容的bash
脚本,它应该回显如下所述的输出:
输入文件: file.txt
host1a
host2b
host3c
host4e
我希望我的输出如下:
--START--
opt1:host1a
opt2:host2b
opt3:host3c
opt4:host4e
--END--
有很多可能性,例如尝试这种方式。
#!/bin/bash
opt="1";
while read line;
do
if [ ! -z "$line" ]
then
echo "opt$opt:$line"
opt=$(($opt+1))
fi
done <your_input_file.txt
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.