How to extract field from variable more efective

Hi,
I know that simple way to do this is var=`echo $line | awk '{print $5}'`
But maybe there is shorter way to do this ?

Also maybe there is some way to assign all fileds from line separated by lets say ":" to some variables
instead of
var1=`echo $line | awk '{print $1}'`
var2=`echo $line | awk '{print $2}'`
.....

Peter

set -- $line
echo $1 $2 ...

What if the fileds in line are separated by : or ~ ?

found that i can export IFS=":".

Ghostdog thanks for this set trick.

You can also use "cut".

Maybe somebody know some page or forum with shell scripting optimalization ? or some tips and triks

this is very usefull:

file:
sda:asd:asd
asd:awq:qwe
das:wer:tyu
asd:wer:123
asd:234:456

export IFS=":"
while read a b c;do echo $a $b $c;done < test

With ksh93 and bash you could use something like this:

$ str="one:two-three" oIFS=$IFS IFS=':-' a=($str) IFS=$oIFS
$ echo ${a[0]}
one
$ echo ${a[1]}
two
$ echo ${a[2]}
three

With zsh:

% str=one:two:three
% a=(${(s.:.)str})   
% echo $a[1]
one
% echo $a[2]
two
% str=one-two-three
% a=(${(s.-.)str})   
% echo $a[3]         
three

What are the main differences between zsh and ksh ? do you know some web page where i can read about those diffs.
I have some old version of ksh, and i'm not a SE and can't install new one.

Where i can find ksh93 for sun ?

Read the Z-Shell User Guide.

You have it as /usr/dt/bin/dtksh on Solaris.

yes i have ; so where i can read about differencess between ksh and ksh93 ?

KornShell

Edit: Sorry, I misread the question.

Check this.