[Please note that the actual contents of file have no reln with the query]
I need to get the count of minimum columns per line. i.e. in above case, it should come out to be 1 since the last line only has 1 column.
I tried following code:
minCount = 0
wordCountPerLine = 0
while true;
do
read myLine || break
for (i =0 ; i < NF ; i++)
do
$lineCount = $wordCountPerLine +1
done
if ($minCount < $wordCountPerLine )
then
$minCount = $wordCountPerLine
fi
wordCountPerLine =0
done < [File Name]
Have 2 queries:
1 > Will this work !!!! ???
2 > The reason I myself cannot answer the 1st query is for the following errors:
line 3: minCount : command not found
line 4: wordCountPerLine : command not found
line 22: syntax error near unexpected token `('
line 22: ` for (i =0 ; i < NF ; i++)'
This just fixes the syntax errors; it doesn't touch the logic:
minCount=0
wordCountPerLine=0
while read myLine
do
for (( i=0 ; i < NF ; i++ ))
do
lineCount=$(( $wordCountPerLine + 1 ))
done
if [ $minCount -lt $wordCountPerLine ]
then
minCount=$wordCountPerLine
fi
wordCountPerLine=0
done < [File Name]