The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Assigning output to a variable jpmena Shell Programming and Scripting 3 03-27-2008 01:39 AM
assigning values to a variable trichyselva UNIX for Dummies Questions & Answers 3 12-13-2007 10:55 PM
Assigning Value of variable janemary.a Shell Programming and Scripting 2 05-11-2007 02:53 AM
assigning variable value using echo shellburger Shell Programming and Scripting 2 07-11-2005 08:52 AM
assigning a variable containing hostname esham Shell Programming and Scripting 4 03-07-2005 09:00 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 07-15-2006
Registered User
 

Join Date: Jul 2006
Posts: 13
Assigning a value to variable

Another newbie to Unix scripting Q..

How do you assign a value resulting from a command, such as awk, to a variable.

I am currently trying:-

$awk '{print $1}' file1 > variable1

with no change to $variable1.

The line:

$awk '{print $1}' file1

does print the first line of the file, so this is not an issue...

Cheers
Reply With Quote
Forum Sponsor
  #2  
Old 07-15-2006
tayyabq8's Avatar
Moderator
 

Join Date: Nov 2004
Location: Bahrain
Posts: 555
In ksh:
Code:
var=`awk '{print $1}' yourfile`
{print $1} will print first column not the first record.

Regards,
Tayyab
Reply With Quote
  #3  
Old 07-15-2006
Registered User
 

Join Date: Jul 2006
Posts: 13
Ah ok, my file only has one column per line in any case, so it is not an issue here.
Reply With Quote
  #4  
Old 07-15-2006
Registered User
 

Join Date: Jul 2006
Posts: 13
Thanks shereenmotor, adding ` ` around the awk statement allows the variable to take the result value of that statement.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 11:38 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0