concat fields

hi

I have a file, I need to concatenate depening on the no of columns i need to concatenate.
for example i need to concatenate field1,filed34,field2( no of columns is not always 3, it can be any number of fields)
concat.ksh field1 field34 field2

how to achieve this, is there any argv ,argc equivalent in ksh.

Hope i am clear

Mark.

You shoud look at the $# and $1, $2,... constructs for ksh. In short $# gives you the number of command line parameters, and $1, $2 gives the parameter1, parameter2. Read man ksh for more details.

just remove the spaces in each line using sed

cat file|while read line
do
sed 's/ //'
done>output_file

sorry , i didn't phrase the question correctly.
actually i have those particular fields that needs to be concatenated in a variable.

like this
var1 = 1 24 3

so i need to concatenate these fields, please let me know.

Thanks
Mark.

start with awk

#!/bin/ksh
# $1 $2 $3 equal a field number  eg, 1 7 32
echo "$myvariable" | awk -v one=$1 -v two=$2 -v three=$3 '{ print $one $two $three  }' | read new_variable
# new_variable has the three fields concatenated

Jim, this works if we know how many fields we are concatenating.,

in my case, i have n number of fields in the variable that needs to be concatenated.

How can i achieve this. Thanks all for your help.

Another way (assume single space as field separator)

var='1 24 3'
cut -d' ' -f$(echo $var|sed 's/ /,/g')

Jean-Pierre.

echo $var | tr -cd [:digit:] 

Thanks guys, Actually my question is

if
1) i have a variable say var=1,9,2 .....etc (
2) I have a file with 10 fields file.dat
3) I need to concatenate $1$9$2 ... from file.dat(I can have more than 3 fields to concatenate.)

I know how can i do if i have constant fields but no of fields to concatenate varies for each file and i need to write a common script to take of this.

Please any suggestions or solution is appreciated.

Thanks
Mark.

awk -v var="1,6,4,2" '
BEGIN { n = split( var, arr, "," ) }
{ for( i = 1 ; i <= n ; ++i )
       printf( "%s" , $arr )
   printf( "\n" )
}' file

Thanks Anbu.