affect variable


Login or Register to Reply

 
Thread Tools Search this Thread
# 1  
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
# 2  
Quote:
Originally Posted by kamel.seg
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
# 3  
Change var = awk '{print $1}' file1
to
var = `awk '{print $1}' file1`
# 5  
Quote:
Originally Posted by kamel.seg
i get this error
var: command not found ??
Drop the spaces around the =

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

# 6  
it works well thanks Smilie

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?
# 7  
Quote:
Originally Posted by kamel.seg
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

Code:
echo "$var" > my.file

Login or Register to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Having too many connections could affect performance ?
alexcol
Good evening, i need your help please I will try to describe the scenario briefly: In a Telecom Production system application receives a certain files called CDRs(call detail records) to be processed by doing some operating systems operations and then database operations like creating indexes...... UNIX and Linux Applications
4
UNIX and Linux Applications
affect a exploded a string into an array
ripat
I would like to affect an exploded string into an array. one:two::fourinto an array: a => one a => two a => a => four Quite simple in other languages with functions like explode() or split(). The best I could come up with was this: until do token=${string%%:*} # takes the...... Shell Programming and Scripting
8
Shell Programming and Scripting
.profile - changes don't affect the login
myle
I have modified the .profile in my profile and I don't see any effect. Why the changes don't have effect? I tried both on the account at a server where I have limited permissions as user and to my local pc (as user). Is it the .profile overridden by some other file? It looks weird because I...... UNIX for Dummies Questions & Answers
8
UNIX for Dummies Questions & Answers
making new default gateway take affect
BG_JrAdmin
How do you make the changes take affect when you change the subnet masks or default router without rebooting?... Solaris
1
Solaris
changig uid and the affect it will have
d__browne
Hello, I have 2 sun servers. We are running Oracle apps. We have to apply patches to both servers whenever a patch needs to be applied for Oracle. We use the same username eg. applmgr on both servers. We have a shared patch area which we can run the patch from on both boxes. the uid for...... UNIX for Advanced & Expert Users
2
UNIX for Advanced & Expert Users

Featured Tech Videos