is there a way to assing variable a value that is output of a program in awk script?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers is there a way to assing variable a value that is output of a program in awk script?
# 1  
Old 08-04-2012
is there a way to assing variable a value that is output of a program in awk script?

Hi there is there a way to assing variable a value that is output of a program in awk script. For e.g., I did
Code:
 temp=(`grep "[datafeed.php]" $5 | cut -f8 -d' '`)

but it does not work.
Any advice???
Thanks in advance!!! Smilie
# 2  
Old 08-04-2012
Either
Code:
temp=`grep "[datafeed.php]" $5 | cut -f8 -d' '`
or 
 temp=$(grep "[datafeed.php]" $5 | cut -f8 -d' ')

would assign the value of the 8th field in the matching line, provided there was one.
This User Gave Thanks to Skrynesaver For This Post:
# 3  
Old 08-04-2012
Quote:
Originally Posted by Skrynesaver
Either
Code:
temp=`grep "[datafeed.php]" $5 | cut -f8 -d' '`
or 
 temp=$(grep "[datafeed.php]" $5 | cut -f8 -d' ')

would assign the value of the 8th field in the matching line, provided there was one.
Thanks a lot !!! Smilie
# 4  
Old 08-05-2012
Try using the awk -v temp=$temp option, if it works on your system.
grep may output several lines if there are several matches in $5 so temp might end up with several blank separated data which in turn would inhibit above option.
From the linux mawk man page:
Quote:
command | getline var : pipes a record from command into var.
might give you the desired result.

Last edited by RudiC; 08-05-2012 at 07:41 AM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Using variable output in awk

Hi, I am trying to use variable output in awk to append a string to a word in a line. But that is not happening. Could you please help me on this. YouTube Video Tutorial: How to Use Code Tags and Format Posts @UNIX.com The below is the code #!/bin/ksh set -x src=/users/oracle/Temp... (2 Replies)
Discussion started by: pvmanikandan
2 Replies

2. Shell Programming and Scripting

Sending output of program into subsequent commands (i.e. awk/sort)

Hi, I have identified how to use command chaining as per below on a file, to capture the header of a file, as well as the line containing the C: drive. $ cat test.txt Filesystem Size Used Avail Use% Mounted on rootfs 237G 153G 84G 65% / none 237G 153G 84G ... (6 Replies)
Discussion started by: sand1234
6 Replies

3. Shell Programming and Scripting

awk question : system output to awk variable.

Hi Experts, I am trying to get system output to capture inside awk , but not working: Please advise if this is possible : I am trying something like this but not working, the output is coming wrong: echo "" | awk '{d=system ("date") ; print "Current date is:" , d }' Thanks, (5 Replies)
Discussion started by: rveri
5 Replies

4. Shell Programming and Scripting

help on awk---- need to assign the output of awk to a variable

hi i want to find the size of a folder and assign it to a variable and then compare if it is greater than 1 gb. i am doin this script, but it is throwing error.... #!/bin/ksh cd . | du -s | size = awk '{print $1}' if size >= 112000 then echo size high fi ERROR : (4 Replies)
Discussion started by: Nithz
4 Replies

5. Shell Programming and Scripting

using awk for setting variable but change the output of this variable within awk

Hi all, Hope someone can help me out here. I have this BASH script (see below) My problem lies with the variable path. The output of the command find will give me several fields. The 9th field is the path. I want to captured that and the I want to filter this to a specific level. The... (6 Replies)
Discussion started by: Cowardly
6 Replies

6. Shell Programming and Scripting

How to assing 'Mon DD' to a variable?

Hi Experts, I am trying to assing a value of current 'Mon DD' to the variable following way: l_day=date '+%b %d' Unfortunately, at the time of run, it says ' +%b %d: not found' Thanks Dip (2 Replies)
Discussion started by: dipeshvshah
2 Replies

7. Shell Programming and Scripting

Using Shell variable within awk program

I have a fixed width text file data.txt delimited by pipe. My requirement is to replace the second column values by *. Problem is that when tried access the shell variable in the awk program, value of shell variable is not printed instead only the name of the variable is printed. Please help to... (4 Replies)
Discussion started by: VijayakumarS
4 Replies

8. Shell Programming and Scripting

Accessing variable from awk program in shell

Hi, I want to access a variable outside the awk program. My program is as below:- I can not access the exact value of k (See the last line of the program). #!/usr/bin/sh j=10 k=1 #k is declared outside awk awk ' BEGIN { i=1; j1="'"$j"'" printf("\n ## Value of j1 is %d ##", j1); ... (2 Replies)
Discussion started by: shouvik.mitra
2 Replies

9. Shell Programming and Scripting

get output of program within a script to a file

I am running a program which probably calla script within, this script executes in a pop window and control returns back to main program. Whilw this script is executing i can see a number of messages being displayed but I cannot read them ,too fast. Is their a way I can redirect those... (3 Replies)
Discussion started by: ruchimca
3 Replies

10. Shell Programming and Scripting

AWK program with array variable

Hi, I made a small awk program just to test array variables. I couldn't find anything wrong with it. But it doesn't give out valid numbers.( just 0.00 ) Do you see any problem that I didn't see? Thanks in advance! Here is the program: ################################## BEGIN { FS =... (4 Replies)
Discussion started by: whatisthis
4 Replies
Login or Register to Ask a Question