Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

test for column numbers in a raw

Status
Not open for further replies.

ogniemi

Technical User
Nov 7, 2003
1,041
PL
VAR=123
(( ${#VAR} == 3 ))


Ho to do similiar test for columns delimetered with space(es) or tab(s) ?

I need to be sure that I have exactly N columns in raw.

-------------------------------
cat list |&

while read -p
do
(( ${#REPLY} == 3 )) && set `echo $REPLY` <--- here should test for columns
.....
-------------------------------

"list" file contains lines with columns delimeteres either by space(es) or tab(s-)


 
Hi

What shell ? [tt]bash[/tt] can put the value in an array then you test the array size.
man bash said:
-a aname
The words are assigned to sequential indices
of the array variable aname, starting at 0.

Or see the [tt]wc[/tt] ( word count ) command with -w option.
man wc said:
-w, --words
print the word counts

Feherke.
 
thx.

I was thinking about 'wc" but I expected there is a similiar way for columns - "(( ${#VAR} == 3 ))"


BTW:

How to print in awk NF-1 column?

thx
r,m.
 
ok, i have it...

# echo 1 2 3 4 5|awk '{print $NF-1}'
4
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top