Shell小程序

1、保持顺序并消除重复行

#!/bin/bash

unset lines
# while read line ; do
while read line || [ -n "$line" ]; do
# echo 'lines length: '${#lines[@]}

# echo 'read:'$line' '${#line}

if !(echo "${lines[@]}" | grep -w $line &>/dev/null); then
# echo 'Not Found'
lines=("${lines[@]}" $line)
fi
done

for line in ${lines[*]}
do
echo $line
done

posted @ 2017-01-16 10:03  大山山  阅读(173)  评论(0编辑  收藏  举报