Sponsored Content
Top Forums Shell Programming and Scripting Substitute variable inside nawk Post 302903443 by mohtashims on Tuesday 27th of May 2014 04:40:55 PM
Old 05-27-2014
Substitute variable inside nawk

Hi,

I need to set "prd" in the below command to a unix variable

Code:
nawk '/^#/ {next} FNR==NR {prd[$0];next} !($0 in prd)'

So, this is what i did

Code:
fname=prd   // unix shell variable

nawk -v fname=$fname '/^#/ {next} FNR==NR {fname[$0];next} !($0 in fname)'

But the value of fname i.e "prd" is not getting substituted in the command.

Can you tell me why ?

Code:
OS: SunOS mymac 5.10 Generic_150400-09 sun4v sparc SUNW,SPARC-Enterprise-T5220

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Substitute variable values

Hi, I am trying to redefine the value of a variable based on another variable value. And I want to read in my variables from a enviroment file in the end -- at least I think so. But 1st here's what I want I need to get working: var_1="11 10 9 8 7 6 5 4 3 2 1" var_2=3 var_3=4 So I want... (12 Replies)
Discussion started by: John Rihn
12 Replies

2. UNIX for Dummies Questions & Answers

Substitute Variable

Can anyone tell me what is the purpose of a substitute variable in the unix programming language and give an example where it may be used? Thanks! (0 Replies)
Discussion started by: mmg2711
0 Replies

3. Shell Programming and Scripting

case command inside awk/nawk

well I found lot of topics about awk..about if command in awk.. but I had to implement this: nawk -F"|" ' $47 ~ /0R0011/ { print > ("/home/user/M/MC.tmp" )} $47 ~ /0R0012/ { print > ("/home/user/M/DuSI.tmp" )} $47 ~ /0R0014/ { print > ("/home/user/M/FF.tmp" )} $47 ~ /0R0018/ { print >... (9 Replies)
Discussion started by: abdulaziz
9 Replies

4. Shell Programming and Scripting

using cp command inside nawk

Hello I have facing issue while using cp command inside nawk block. #!/bin/ksh my_name=$1 nawk -v my_name1=$my_name 'BEGIN { n = split(my_name1,names,":"); for (i=1;i<=n;i++) { print names; cpcmd = "cp " /tmp/test.txt" " ./sample system(cpcmd) } exit }' exit 0 i'am getting... (1 Reply)
Discussion started by: piscean_n
1 Replies

5. Shell Programming and Scripting

variable inside variable inside loop headache

Hi Gurus I have a file called /tmp/CMDB which looks like this serial: 0623AN1208 hostname: server1 model: x4100 assetID: 1234 I am writing a for loop that will go through this file line by line creating a variable of itself. Using the first iteration of the loop (i.e. the first line) as... (6 Replies)
Discussion started by: hcclnoodles
6 Replies

6. Shell Programming and Scripting

substitute variable for values in perl

hi all, how do i assign values passed in from command line to and sql statement in perl ?? e.g i want to assign :name1 and :Name2 to be whatever is passed into the perl script command line my $sqlStr = "select * from test_table where column1 = upper(nvl(:name1, name1 )) and column2... (1 Reply)
Discussion started by: cesarNZ
1 Replies

7. Shell Programming and Scripting

substitute variable in bash

hi all, Assume that i a having the following three lines in an executable file #/bin/bash a=Tue Tue=1 When i give echo $a the value should be 1, how to do this. Your suggestions please. Thanks in advance, Anish (4 Replies)
Discussion started by: anishkumarv
4 Replies

8. Shell Programming and Scripting

Reading input record from inside nawk

Hi friends, I have small query with reg to awk search pattern.. below is my sample file and code which i tried.. $ cat file.txt xxx,yyyyy,messageID,sha xxxx,errorcode,messageID,name in the above sample file - let assume I know the errorcode(2nd record) using which I want to... (2 Replies)
Discussion started by: Shahul
2 Replies

9. Shell Programming and Scripting

AWK variable substitute issue

dear, I have below file called folderlist.txt # ParentFolder environment_flag SubFolders triss 1 checksum bookstructure 1 fx 1 checksum_GMDB I have a script which which will create the folders under... (3 Replies)
Discussion started by: manas_ranjan
3 Replies

10. UNIX for Beginners Questions & Answers

How to avoid arguments inside Nawk command?

Hi, Here is my command print $2 was meant to select the second column however, it is getting substituted with the second argument that was passed to the script. Can you please tell me how can I resolve this ? (6 Replies)
Discussion started by: mohtashims
6 Replies
GETLASTLOGX(3)						   BSD Library Functions Manual 					    GETLASTLOGX(3)

NAME
getlastlogx, getutmp, getutmpx, updlastlogx, updwtmpx, utmpxname -- user accounting database functions LIBRARY
Standard C Library (libc, -lc) SYNOPSIS
#include <utmpx.h> struct lastlogx * getlastlogx(const char *fname, uid_t uid, struct lastlogx *ll); void getutmp(const struct utmpx *ux, struct utmp *u); void getutmpx(const struct utmp *u, struct utmpx *ux); int updlastlogx(const char *fname, uid_t uid, struct lastlogx *ll); int updwtmpx(const char *file, const struct utmpx *utx); int utmpxname(const char *fname); DESCRIPTION
The getlastlogx() function looks up the entry for the user with user id uid in the lastlogx(5) file given by fname and returns it in ll. If the provided ll is NULL, the necessary space will be allocated by getlastlogx() and should be free()d by the caller. The getutmp() function fills out the entries in the struct utmp u with the data provided in the struct utmpx ux. getutmpx() does the oppo- site, filling out the entries in the struct utmpx ux with the data provided in the struct utmp u, and initializing all the unknown fields to 0. The sole exception is the ut_type field, which will be initialized to USER_PROCESS. The updlastlogx() function tries to update the information for the user with the user id uid in the lastlogx(5) file given by fname with the data supplied in ll. A struct lastlogx is defined like this: struct lastlogx { struct timeval ll_tv; /* time entry was created */ char ll_line[_UTX_LINESIZE]; /* tty name */ char ll_host[_UTX_HOSTSIZE]; /* host name */ struct sockaddr_storage ll_ss; /* address where entry was made from */ }; All the fields should be filled out by the caller. The updwtmpx() function updates the wtmpx(5) file file with the utmpx(5) entry utx. The utmpxname() function sets the default utmpx(5) database file name to fname. RETURN VALUES
getlastlogx() returns the found entry on success, or NULL if it could not open the database, could not find an entry matching uid in there, or could not allocate the necessary space (in case ll was NULL). utmpxname() returns 1 on success, or 0 if the supplied file name was too long or did not end with 'x'. updlastlogx() and updwtmpx() return 0 on success, or -1 in case the database or file respectively could not be opened or the data not written into it. SEE ALSO
endutxent(3), loginx(3), utmpx(5) HISTORY
The functions getutmp(), getutmpx(), updwtmpx(), and utmpxname() first appeared in Solaris. getlastlogx and updlastlogx first appeared in NetBSD 2.0. BSD
August 26, 2003 BSD
All times are GMT -4. The time now is 04:15 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy