Sponsored Content
Top Forums Programming How to call a variable in awk again ? Post 302999096 by Ethan Stark on Tuesday 13th of June 2017 07:30:56 AM
Old 06-13-2017
27
down vote
You cannot grab the output of an awk system() call, you can only get the exit status. Use the getline/pipe or getline/variable/pipe constructs

Code:
awk '{
    cmd = "your_command " $1
    while (cmd | getline line) {
        do_something_with(line) 
    }
    close(cmd)
}' file

Moderator's Comments:
Mod Comment please use code tags


Ethan Stark

Last edited by jim mcnamara; 06-13-2017 at 09:32 AM.. Reason: code tags
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

does this variable call work--Korn

I am new to the UNIX environment, but not to programming. My intention is to create a 2D array and print it. Since the Korn Shell does not support that kind of variable, the following is my solution right now. I have created a group of variables as follows: table00 table01 table02 table10... (2 Replies)
Discussion started by: morkfard
2 Replies

2. Shell Programming and Scripting

Enviornment Variable in B shell (I call it nested variable)

#!/bin/sh APP_ROOT_MODE1=/opt/app1.0 APP_ROOT_MODE2=/opt/app2.0 APP_ROOT=${APP_ROOT_${APP_MODE}} # enviornment variable APP_MODE will be exported in the terminal where # we run the applciation, its value is string - MODE1 or MODE2 # My intension is: # when export APP_MODE=MODE1... (4 Replies)
Discussion started by: princelinux
4 Replies

3. Programming

Setting environment variable using JNI call

I have function declaration in Java and same function definition written in C programming language.. A JNI call from Java is made to a fuction...Function would set the environment variable { putenv(cEnvString1);} using C-built -in function ..and later return the encrypted string... putenv is... (6 Replies)
Discussion started by: shafi2all
6 Replies

4. Shell Programming and Scripting

Bash: how to call function having it's name in variable?

Hello. Looking for a method of modularizing my bash script, I am stuck with such a problem. For example, I have: MODULE_NAME="test" FUNCTION_NAME="run" How do I can a function with name test_run? (4 Replies)
Discussion started by: FractalizeR
4 Replies

5. Shell Programming and Scripting

Variable names within array call

I am trying to write a piece of code that will call a value from an array. There are multiple arrays that I need to call data from. Only one array needs to be used based on the step within the program. The arrays have the names "cue_0", "cue_1", and so on. I can't figure out how to call a value... (2 Replies)
Discussion started by: vockleya
2 Replies

6. Shell Programming and Scripting

How to call arguments with variable in a script??

Hello, I was wondering if it were possible to call arguments passed to a script using a variable. For example: sh script.sh yes no good bad x=$# while do echo (last argument, then second last etc until first argument) let x=($x-1) done should print out bad good no (4 Replies)
Discussion started by: VanK
4 Replies

7. Shell Programming and Scripting

Passing awk variable in perl -e call

Hi. I am on a Solaris box and have an awk script which calls perl via the command line: timeTester="'"`perl -e 'use Time::Local;my $time = timelocal(10,10,10,10,10,2011 );print $time'`"'" But I want to pass awk variables into this call. These are the example awk variables: secondField = 10... (0 Replies)
Discussion started by: pedro6994
0 Replies

8. Shell Programming and Scripting

Call a awk script with variable and input filename

HI, MY question is a very simple one: if i want to call an awk script with the input file name and also pass a variable value , then how to do it. #>awk -f my_script.awk -v variable=value my_inputfile.txt I can't do it like this. throws error: awk: my_script.awk:18:... (0 Replies)
Discussion started by: Onkar Banerjee
0 Replies

9. Shell Programming and Scripting

Dereferencing variable inside egrep call

Hi guys I am trying to dereference a variable inside 'egrep -v ' command and getting a 'egrep: syntax error' : $ echo $exclude_list ts584d hf584db for i in `echo $exclude_list`; do egrep -v ${i} my_file done egrep: syntax error egrep: syntax error The syntax of the loop is correct.... (1 Reply)
Discussion started by: aoussenko
1 Replies

10. UNIX for Beginners Questions & Answers

How to call variable inside a function globally?

Hi Gurus, Is there a way to call a variable inside a function anywhere within the script? Thanks. BR, Ernesto (2 Replies)
Discussion started by: ernesto
2 Replies
GETLINE(3)						     Linux Programmer's Manual							GETLINE(3)

NAME
getline, getdelim - delimited string input SYNOPSIS
#define _GNU_SOURCE #include <stdio.h> ssize_t getline(char **lineptr, size_t *n, FILE *stream); ssize_t getdelim(char **lineptr, size_t *n, int delim, FILE *stream); DESCRIPTION
getline() reads an entire line, storing the address of the buffer containing the text into *lineptr. The buffer is null-terminated and includes the newline character, if a newline delimiter was found. If *lineptr is NULL, the getline() routine will allocate a buffer for containing the line, which must be freed by the user program. Alter- natively, before calling getline(), *lineptr can contain a pointer to a malloc()-allocated buffer *n bytes in size. If the buffer is not large enough to hold the line read in, getline() resizes the buffer to fit with realloc(), updating *lineptr and *n as necessary. In either case, on a successful call, *lineptr and *n will be updated to reflect the buffer address and size respectively. getdelim() works like getline(), except a line delimiter other than newline can be specified as the delimiter argument. As with getline(), a delimiter character is not added if one was not present in the input before end of file was reached. RETURN VALUE
On success, getline() and getdelim() return the number of characters read, including the delimiter character, but not including the termi- nating null character. This value can be used to handle embedded null characters in the line read. Both functions return -1 on failure to read a line (including end of file condition). ERRORS
EINVAL Bad parameters (n or lineptr is NULL, or stream is not valid). EXAMPLE
#define _GNU_SOURCE #include <stdio.h> #include <stdlib.h> int main(void) { FILE * fp; char * line = NULL; size_t len = 0; ssize_t read; fp = fopen("/etc/motd", "r"); if (fp == NULL) exit(EXIT_FAILURE); while ((read = getline(&line, &len, fp)) != -1) { printf("Retrieved line of length %zu : ", read); printf("%s", line); } if (line) free(line); return EXIT_SUCCESS; } CONFORMING TO
Both getline() and getdelim() are GNU extensions. They are available since libc 4.6.27. SEE ALSO
read(2), fopen(3), fread(3), gets(3), fgets(3), scanf(3) GNU
2001-10-07 GETLINE(3)
All times are GMT -4. The time now is 06:40 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy