【发布时间】:2015-06-30 21:21:40
【问题描述】:
我正在循环浏览 txt 文件中的制表符分隔的行。此 txt 文件是 xml/xslt 进程的输出,并且有重复项。下面我正在寻找一个使用 txt 文件的解决方案,但使用 XSLT 的解决方案同样值得赞赏。请查看示例 txt 文件。
txtfile.txt:第 3 行与第 1 行重复
hello@example.com running 1111
puppy@kennel.com running 9876
hello@example.com running 1111
husky@siberia.com shutdown 1234
puppy@kennel.com running 9876
hello@example.com running 1111
我的问题是:可以在循环中跳过重复的行,以便循环只处理唯一的行吗?在这种情况下,如何配置循环第 1、2、4 行并跳过第 3、5、6 行?
我当前读取重复项的工作循环:
while read name status num
do
echo "<tag1>"
echo "<tag2>"$name"</tag2>"
echo "<tag3>"$status"</tag3>"
echo "<tag2>"$num"</tag2>"
echo "</tag1>"
done < txtfile.txt
在我的 txtfile 中有数百行,近一半是重复的,所以这对我来说是个大问题!任何想法/解决方案表示赞赏。提前致谢。
【问题讨论】:
-
可能会使用一个排序的唯一列表,比如
<(cat txtfile.tx | sort | uniq)。
标签: linux bash shell loops xslt