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
Storing count(*) into unix variable mervinboyz Shell Programming and Scripting 1 03-26-2008 08:14 PM
Storing a variable? hoover90 Shell Programming and Scripting 4 01-26-2008 06:39 PM
Using 'defaults read' and storing the output in a variable davewg Shell Programming and Scripting 0 11-14-2007 05:04 AM
Storing the output into a variable ravi raj kumar UNIX for Dummies Questions & Answers 7 12-11-2006 06:14 AM
Storing values in variable matrixmadhan Shell Programming and Scripting 1 03-31-2005 10:56 PM

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

Join Date: May 2006
Posts: 12
storing output of awk in variable

HI
I am trying to store the output of this awk command
awk -F, {(if NR==2) print $1} test.sr
in a variable when I am trying v= awk -F, {(if NR==2) print $1} test.sr
$v = awk -F, {(if NR==2) print $1} test.sr
but its not working out .
Any suggestions
Thanks
Arif
Reply With Quote
Forum Sponsor
  #2  
Old 05-07-2006
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 4,297
Code:
v=$(awk -F, '{(if NR==2) print $1}' test.sr)

Last edited by jim mcnamara; 05-07-2006 at 01:51 PM.
Reply With Quote
  #3  
Old 05-07-2006
Registered User
 

Join Date: Apr 2006
Posts: 26
Here is a script in csh that works.

Notice the back ticks before awk and after the file name , your test file name.
It worked fine for me.

#!/bin/csh

set v=`awk -F, 'NR == 2 {print $1}' test.sr`
echo $v >> outputfile "this will append the value of v to a file"

Last edited by bdsffl; 05-07-2006 at 12:25 PM.
Reply With Quote
  #4  
Old 05-07-2006
Registered User
 

Join Date: May 2006
Posts: 12
Thanks everybody for your help ,I got it .
Thanks
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 10:32 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