shell - How to check array doesn't contain line in bash scripting -


i reading data file line line , storing array, can access later array compare other files data.

now, input file has redundancy, how add unique lines array. need check while adding array itself?

below code using read data file:

while read line     //how check array contains line???         <code adding array> done <"$file" 

you can use associative array this:

declare -a ulines  while ifs= read -r line;    [[ ! ${ulines["$line"]} ]] && echo "$line" && ulines["$line"]=1 done < "$file" 

this print unique lines on stdout preserving original order in input file.


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -