Sponsored Content
Top Forums UNIX for Beginners Questions & Answers How to assign a value to a variable in awk scripting? Post 303038175 by bhagya123 on Tuesday 27th of August 2019 12:29:46 PM
Old 08-27-2019
How to assign a value to a variable in awk scripting?

Hi,

I am trying to assign a value using below command and it is assigning the command to the variable not the output of the command?

Code:
out_value="echo $0 | cut -c 9-11";

How can i assign the output to the variable instead of whole command?

This is inside my awk script

Last edited by Don Cragun; 08-28-2019 at 01:21 AM.. Reason: Add CODE tags, again.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk: assign a printf value to a variable

Is there any way to something like this?: variable=printf("%30s",var1) Thx. (2 Replies)
Discussion started by: Klashxx
2 Replies

2. Shell Programming and Scripting

assign value to variable using AWK

Dear Friends I have text file as like below, AAAAA|BHBHBH|VERYSMART AAAAA| KKKKKK|GOOD BBBBBB|JJJJJJJ|VERYGOOD CCCCC|HJHJHJ|BETTER CCCCC|UUUUU|GOOD i need to split into seperate files based on column 1 like as below AAAAA.TXT contains -------------------- BHBHBH.VERYSMART... (4 Replies)
Discussion started by: HAA
4 Replies

3. Shell Programming and Scripting

Assign o/p of awk to a variable

:confused: Hi UNIX gurus, I am facing a typical problem while assigining while assigining output of awk to a variable. I have a fixed length file say myinputfile.txt When I allow the value/output of an awk to be redirected to a file, it works fine. i.e. awk "/^.{232}$acctNum/ {... (8 Replies)
Discussion started by: c2b2
8 Replies

4. Shell Programming and Scripting

assign awk output to bash variable

greetings all, I am have a heck of a time trying to accomplish a very simple thing. I have an array of "shortname<spaces>id" created from a dscl output. I want to assign shortname=word1 and id=word2. I have tried shortname=$(${textArray} | awk '{print $1}') - and get 'awk : cannot open... (3 Replies)
Discussion started by: macnetdaemon
3 Replies

5. Shell Programming and Scripting

awk: assign variable with -v didn't work in awk filter

I want to filter 2nd column = 2 using awk $ cat t 1 2 2 4 $ VAR=2 #variable worked in print $ cat t | awk -v ID=$VAR ' { print ID}' 2 2 # but variable didn't work in awk filter $ cat t | awk -v ID=$VAR '$2~/ID/ { print $0}' (2 Replies)
Discussion started by: honglus
2 Replies

6. Shell Programming and Scripting

assign awk's variable to shell script's variable?

Dear All, we have a command output which looks like : Total 200 queues in 30000 Kbytes and we're going to get "200" and "30000" for further process. currently, i'm using : numA=echo $OUTPUT | awk '{print $2}' numB=echo $OUTPUT | awk '{print $5}' my question is : can I use just one... (4 Replies)
Discussion started by: tiger2000
4 Replies

7. 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

8. Shell Programming and Scripting

Assign a variable with awk

I launch 'netstat -a', if string 'ESTABLISHED' found, then VAR=1 #!/bin/bash VAR=0; netstat -a | awk '$6 ~ /ESTABLISHED/ {VAR=1}' I cannot find the right syntax. thanx guys! (3 Replies)
Discussion started by: arpagon
3 Replies

9. Shell Programming and Scripting

Assign awk gsub result to a variable

Hello, I have searched but failed to find what exactly im looking for, I need to eliminate first "." in a output so i can use something like the following echo "./abc/20141127" | nawk '{gsub("^.","");print}' what i want is to use gsub result later on, how could i achieve it? Let say... (4 Replies)
Discussion started by: EAGL€
4 Replies

10. UNIX for Beginners Questions & Answers

How can I assign awk's variable to shell script's variable?

I have the following script, and I want to assign the output ($10 and $5) from awk to N and L: grdinfo data.grd | awk '{print $10,$5}'| read N L output from gridinfo data.grd is: data.grd 50 100 41 82 -2796 6944 0.016 0.016 3001 2461. where N and L is suppose to be 3001 and 100. I use... (8 Replies)
Discussion started by: geomarine
8 Replies
doconfig(3NSL)                                         Networking Services Library Functions                                        doconfig(3NSL)

NAME
doconfig - execute a configuration script SYNOPSIS
cc [ flag ... ] file ... -lnsl [ library ... ] # include <sac.h> int doconfig(int fildes, char *script, long rflag); DESCRIPTION
doconfig() is a Service Access Facility library function that interprets the configuration scripts contained in the files </etc/saf/pmtag/_config>, </etc/saf/_sysconfig>, and </etc/saf/pmtag/svctag>, where pmtag specifies the tag associated with the port moni- tor, and svctag specifies the service tag associated with a given service. See pmadm(1M) and sacadm(1M). script is the name of the configuration script; fildes is a file descriptor that designates the stream to which stream manipulation opera- tions are to be applied; rflag is a bitmask that indicates the mode in which script is to be interpreted. If rflag is zero, all commands in the configuration script are eligible to be interpreted. If rflag has the NOASSIGN bit set, the assign command is considered illegal and will generate an error return. If rflag has the NORUN bit set, the run and runwait commands are considered illegal and will generate error returns. The configuration language in which script is written consists of a sequence of commands, each of which is interpreted separately. The fol- lowing reserved keywords are defined: assign, push, pop, runwait, and run. The comment character is #; when a # occurs on a line, every- thing from that point to the end of the line is ignored. Blank lines are not significant. No line in a command script may exceed 1024 char- acters. assign variable=value Used to define environment variables. variable is the name of the environment variable and value is the value to be assigned to it. The value assigned must be a string constant; no form of parameter substitution is available. value may be quoted. The quoting rules are those used by the shell for defining environment variables. assign will fail if space cannot be allocated for the new variable or if any part of the specification is invalid. push module1[, module2, module3, . . .] Used to push STREAMS modules onto the stream designated by fildes. module1 is the name of the first module to be pushed, module2 is the name of the second module to be pushed, etc. The command will fail if any of the named modules cannot be pushed. If a module cannot be pushed, the subsequent modules on the same command line will be ignored and modules that have already been pushed will be popped. pop [module] Used to pop STREAMS modules off the designated stream. If pop is invoked with no arguments, the top module on the stream is popped. If an argument is given, modules will be popped one at a time until the named module is at the top of the stream. If the named module is not on the designated stream, the stream is left as it was and the command fails. If module is the special keyword ALL, then all mod- ules on the stream will be popped. Note that only modules above the topmost driver are affected. runwait command The runwait command runs a command and waits for it to complete. command is the pathname of the command to be run. The command is run with /usr/bin/sh -c prepended to it; shell scripts may thus be executed from configuration scripts. The runwait command will fail if command cannot be found or cannot be executed, or if command exits with a non-zero status. run command The run command is identical to runwait except that it does not wait for command to complete. command is the pathname of the command to be run. run will not fail unless it is unable to create a child process to execute the command. Although they are syntactically indistinguishable, some of the commands available to run and runwait are interpreter built-in commands. Interpreter built-ins are used when it is necessary to alter the state of a process within the context of that process. The doconfig() interpreter built-in commands are similar to the shell special commands and, like these, they do not spawn another process for execution. See sh(1). The built-in commands are: cd ulimit umask RETURN VALUES
doconfig() returns 0 if the script was interpreted successfully. If a command in the script fails, the interpretation of the script ceases at that point and a positive number is returned; this number indicates which line in the script failed. If a system error occurs, a value of -1 is returned. When a script fails, the process whose environment was being established should not be started. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |MT-Level |Unsafe | +-----------------------------+-----------------------------+ SEE ALSO
sh(1), pmadm(1M), sacadm(1M), attributes(5) NOTES
This interface is unsafe in multithreaded applications. Unsafe interfaces should be called only from the main thread. SunOS 5.10 30 Dec 1996 doconfig(3NSL)
All times are GMT -4. The time now is 04:13 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy