Sponsored Content
Full Discussion: Passing variables into AWK
Top Forums Shell Programming and Scripting Passing variables into AWK Post 302713129 by pamu on Wednesday 10th of October 2012 10:05:33 AM
Old 10-10-2012
Quote:
Originally Posted by Boomn4x4
Thanks, that saved some trouble, however, my output is putting out literal text, not the variable value. My output:

myip1 myhost1.test.com myhost1
myip2 myhost2.test.com myhost2
myip1 myhost1.test.com myhost1
myip2 myhost2.test.com host2
Remove double quotes and you don't need printf also.. In double quotes it is considered as a string..Smilie

Code:
if ( ) {print myip1, mqhost1".test.com", mqhost1}


Last edited by pamu; 10-10-2012 at 11:37 AM.. Reason: corrected..
This User Gave Thanks to pamu For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Passing Variables to AWK

Does anybody have an explanation for the following: The following scripts runs fine on IRIX64 6.5 but has bugs on Solaris 8. #! /bin/sh echo run only on an SGI machine echo type in linenumber read j echo value read value awk -f rmspass2 level=$value $j'step1.mlf' When the script is... (5 Replies)
Discussion started by: AreaMan
5 Replies

2. Shell Programming and Scripting

Passing Variables to Awk

Hi I have a unix shell script with an awk statement. I would like to print some of the fields of an input file. However, I would like to print them dynamically, ie by passing the literal $1 $3 into the script to define the output. I have tried the following: variable1='$1' awk... (2 Replies)
Discussion started by: Bab00shka
2 Replies

3. Shell Programming and Scripting

Passing awk Variables

I am trying to pass the results from a variable gathered from awk, however when I echo the 'PARSE' and 'SUB', the response is blank. This is my command. awk -F= '/Unit/''{ PARSE=substr($2,1,5) ; SUB=substr($2,1,1) }' inputfile.lst Is this a kind of valid attempt or am I obligated to declare... (3 Replies)
Discussion started by: gozer13
3 Replies

4. Shell Programming and Scripting

Passing space seprated variables in awk

Hi, How to pass space seprated variables in awk. (HP-UX, sh shell) I have the problem like below: var="Hello" var2="Manu Batham" echo $var2 | awk -v variable=${var} '{ printf "%s %s", variable, $1}' and its output is: Hello Manu while output should be: Hello Manu Batham Please... (4 Replies)
Discussion started by: manubatham20
4 Replies

5. Shell Programming and Scripting

Passing awk variables to shell

Hi. I need to parse file and assign some values to variables, right now i do like below MYHOMEDIR=`awk '/Home/ {print $NF}' output.txt` MYSHELL=`awk '/Shell/ {print $NF}' output.txt` PRGRP=`awk '/Primary/ {print $NF}' output.txt` SECGRP=`awk '/Second/ {print $NF}' output.txt` In this... (10 Replies)
Discussion started by: urello
10 Replies

6. Shell Programming and Scripting

ksh passing to awk multiple dyanamic variables awk -v

Using ksh to call a function which has awk script embedded. It parses a long two element list file, filled with text numbers (I want column 2, beginning no sooner than line 45, that's the only known thing) . It's unknown where to start or end the data collection, dynamic variables will be used. ... (1 Reply)
Discussion started by: highnthemnts
1 Replies

7. Shell Programming and Scripting

PAssing variables to awk arithmetic

Hi all, I am wanting to pass variables from a file to an awk arithmetic formula. When I use the formula with the value it works well. As soon as I make these variables I get an inf (infinity) response. I can certainly echo the variables back and they look correct. My googling for answers has... (3 Replies)
Discussion started by: gafoleyo73
3 Replies

8. Shell Programming and Scripting

Passing variables to awk

Hi guys, I need to fetch data from logfile between two given dates,i got the below code from our forum.It works perfect,but i need to enter the value dynamically to awk while running. awk '/2012 Jun/{p=1}!/2012 Jul/ && prev~/2012 Jul/ && p{p=0}{prev=$0}p' file i tried the below code,but... (4 Replies)
Discussion started by: mohanalakshmi
4 Replies

9. Shell Programming and Scripting

Passing awk variables to bash variables

Trying to do so echo "111:222:333" |awk -F: '{system("export TESTO=" $2)}'But it doesn't work (2 Replies)
Discussion started by: urello
2 Replies

10. Shell Programming and Scripting

awk - passing variables in and out

Am looking to pass some Linux environment variables into AWK , can I simply use the -v option ? awk -F: -v AHOME=$HOME '{ if {rm AHOME/file.txt a=2 } }' config.txt ... (4 Replies)
Discussion started by: alldbest
4 Replies
ATF-TEST-PROGRAM(1)					    BSD General Commands Manual 				       ATF-TEST-PROGRAM(1)

NAME
atf-test-program -- common interface to ATF test programs SYNOPSIS
atf-test-program [-r resfile] [-s srcdir] [-v var1=value1 [.. -v varN=valueN]] test_case atf-test-program -l DESCRIPTION
Test programs written using the ATF libraries all share a common user interface, which is what this manual page describes. NOTE: There is no binary known as atf-test-program; what is described in this manual page is the command-line interface exposed by the atf-c, atf-c++ and atf-sh bindings. In the first synopsis form, the test program will execute the provided test case and print its results to the standard output, unless other- wise stated by the -r flag. Optionally, the test case name can be suffixed by ':cleanup', in which case the cleanup routine of the test case will be executed instead of the test case body; see atf-test-case(4). Note that the test case is executed without isolation, so it can and probably will create and modify files in the current directory. To execute test cases in a controller manner, you need a runtime engine that understands the ATF interface. The recommended runtime engine is kyua(1). You should only execute test cases by hand for debugging pur- poses. In the second synopsis form, the test program will list all available test cases alongside their meta-data properties in a format that is machine parseable. This list is processed by kyua(1) to know how to execute the test cases of a given test program. The following options are available: -l Lists available test cases alongside a brief description for each of them. -r resfile Specifies the file that will receive the test case result. If not specified, the test case prints its results to stdout. If the result of a test case needs to be parsed by another program, you must use this option to redirect the result to a file and then read the resulting file from the other program. Note: do not try to process the stdout of the test case because your program may break in the future. -s srcdir The path to the directory where the test program is located. This is needed in all cases, except when the test program is being executed from the current directory. The test program will use this path to locate any helper data files or utilities. -v var=value Sets the configuration variable var to the value value. SEE ALSO
kyua(1) BSD
March 2, 2014 BSD
All times are GMT -4. The time now is 11:13 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy