I am iterating through a file line by line and put each word into a array and that works. But it also picks up blank lines and puts it as an item in the array, how can I skip the blank lines?
example file
Line 1
line 2
line 3
line 4
line 5
line 6
My code
while read line ; do
myarray[$index]="$line"
index=$(($index+1))
done < $inputfile
Possible psuedo code
while read line ; do
if (line != space);then
myarray[$index]="$line"
fi
index=$(($index+1))
done < $inputfile
Remove the blank lines first with sed
.
for word in `sed '/^$/d' $inputfile`; do
myarray[$index]="$word"
index=$(($index+1))
done
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句