affect variable

hi ,

i want to store variable but i get always error when i excute this command ligne :

var = awk '{print $1}' file1
echo $var

how can i store the var?

thanks

Drop the spaces around = and introduce the $(...) construct.
var=$(awk '{print $1}' file1)
echo $var

Change var = awk '{print $1}' file1
to
var = `awk '{print $1}' file1`

i get this error
var: command not found ??

Drop the spaces around the =

var=$(awk '{print $1}' file1)

it works well thanks :slight_smile:

i want to know if i want to print this $var in new file how can i do it?

awk -F "," '{ print $1","$2","$var,"$4"} file1>file2 ?

how can i print this value of var in new file?

With that awk statement, what are you trying to achieve ? Get the value of $var or print the field denoted by $var ?

To print to a file, you can

echo "$var" > my.file

i want to print the $var in specific emplacement $3 in a line of file like that :

file1
attg,var1,var3,var4
var4,var5,var6,var7
.
.
.

for example if $3= var3 i want to print $var in $3 ?

how can i print $var in $3 ?