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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

test variables based on previous variable count :-)

Status
Not open for further replies.

UsRb

IS-IT--Management
Mar 19, 2007
48
HR
Hi2all!

I'm reading a file which looks like this:
232,544,7656,548
33,45
344,576,7656

User copies and pastes one line:
read i
echo $i| sed 's/,/\n/g' | while read i; do
command
done

Now in next step, I need to know how many "words" were in pasted line and based on that count, test them like this (compare their values):

if [[ word1 = word2 && word2 = word3 && ... ]]; then
ok
else
not ok
fi
 
Hi

You already transformed it into separate lines. From there is one more step to check if all lines are identical :
Code:
echo [navy]$i[/navy][teal]|[/teal] sed [green][i]'s/,/[/i][/green][lime][i]\n[/i][/lime][green][i]/g'[/i][/green] [highlight][teal]|[/teal] sort -u [teal]|[/teal] wc -l[/highlight]
If it outputs 1, all lines are identical.

You not specified your shell, but if it is Bash, its [tt]read[/tt] can read directly into an array. Just a hint.

Feherke.
 
Yes, thank you very much.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top