从文本文件中逐行读取但不用bash重复

时间:2016-01-29 14:07:29

标签: bash

1,bash内容:

#!/bin/bash
file="/home/zjhxmjl/Desktop/111"
while read -r line;do
    sed "s/$/$line/" xiaoxiequanpin.lst >> quanpin_8shenri
    sed -i 's/ //g' quanpin_8shenri
    tr -d '\r'< quanpin_8shenri > quanpin_8shenri.new
    tr -s ' '< quanpin_8shenri.new > quanpin_8shenri.newest
    mv quanpin_8shenri.newest quanpin_8shenri.lst
done <"$file"

2,文件“111”(location / home / zjhxmjl / Desktop /)内容:

19800101
19800102

3,xiaoxiequanpin.lst内容:

aaa
bbb

4,文件“quanpin_8shenri.lst”结果:

aaa19800101
bbb19800101
aaa19800101
bbb19800101
aaa19800102
bbb19800102

5,我想结果:

aaa19800101
bbb19800101
aaa19800102
bbb19800102

所以有人可以给我一些进展吗?

1 个答案:

答案 0 :(得分:1)

将结果传递给sort和uniq:

someprocess | sort | uniq

修改

或简单地说:

someprocess | sort -u