Sponsored Content
Top Forums Shell Programming and Scripting awk - Why can't value of awk variables be passed to external functions ? Post 302926246 by sea on Saturday 22nd of November 2014 08:05:40 AM
Old 11-22-2014
As i see it, not really understanding awk yet, but you're comparing a STRING (a) with an INTEGER (k).
Anyhow, so you pass a list of variables, and when it matches a certain string, you want to call that function?

Must it be awk, because bash works just fine Smilie
Code:
#!/bin/bash
my_func_local() {
    echo "In func: my_func_local $1"
}

for ARG in "${@}";do
    [[ $ARG = a ]] && \
        my_func_local $ARG || \
        echo $ARG
done

Code:
sh script.sh a b c d
In func: my_func_local a
b
c
d

Hope this helps
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

variable passed to awk

Anybody know what's wrong with this syntax? awk -v job="$job" 'BEGIN { FS="|"} {print $1,$2," ",$4," ",$3\n,$5,"\n"}' list It's keeping give me this message: awk: syntax error near line 1 awk: bailing out near line 1 It seems awk has problem with my BEGIN command. Any... (8 Replies)
Discussion started by: whatisthis
8 Replies

2. UNIX for Dummies Questions & Answers

variable passed to awk

Does anybody know how to print a variable passed to awk command? awk -F"|" 'BEGIN {print $job,"\n","Question \n"} {print $1,$2$4," ",$3}' "job=$job1" file1 I am trying to pass job the variable job1. the output is blank. ?? (3 Replies)
Discussion started by: whatisthis
3 Replies

3. Shell Programming and Scripting

awk - arithemetic functions with external variables

I'm trying to get awk to do arithmetic functions with external variables and I'm getting an error that I cannot figure out how to fix. Insight would be appreciated money=$1 rate1=$(awk -F"\t " '/'$converting'/{print $3}' convert.table) rate2=$(awk -F"\t"... (2 Replies)
Discussion started by: DKNUCKLES
2 Replies

4. Shell Programming and Scripting

AWK: Retrieving names of variables passed with -v

I'm an experienced awk user, but this one has me stumped. I have an awk script which is called from a UNIX command line as you'd expect: myscript.awk -v foo=$1 -v bar=$2 filename My question is this: is there a mechanism for determining the names of the -v variables within a script? ... (3 Replies)
Discussion started by: John Mac
3 Replies

5. Shell Programming and Scripting

flags passed to an awk script

I have an awk script script.awk for example and want to pass a flag (let's call it "neat") so that the data is put into nice columns. For example like this awk -v neat -f script.awk fin > fout Then check inside the program if the use has put neat, if yes I output the lines in nice columns,... (1 Reply)
Discussion started by: kristinu
1 Replies

6. Shell Programming and Scripting

arithmetic from csh variable passed to awk

I have the following code in a csh script I want to pass the value of the variable sigmasq to the awk script so that I can divide $0 by the value of sigmasq grep "Rms Value" $f.log \ | awk '{ sub(/*:*\.*/,x); \ print... (2 Replies)
Discussion started by: kristinu
2 Replies

7. Shell Programming and Scripting

Assign value to external variables from awk

Hello I have a text file with the next pattern Name,Year,Grade1,Grade2,Grade3 Name,Year,Grade1,Grade2,Grade3 Name,Year,Grade1,Grade2,Grade3 I want to assign to external variables the grades using the awk method. After i read the file line by line in order to get the grades i use this ... (2 Replies)
Discussion started by: Spleshmen
2 Replies

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

9. Shell Programming and Scripting

awk processing of passed variables

Currently have this: set current=192.168.0.5 set servicehost = `echo $current | awk -F. '{print $4}'` echo $numberoffields 5 ..but would like to reduce # of variables and eliminate echo to have something like this: set servicehost = `awk -v s="$current" -F. 'BEGIN{print $2}'`But... (3 Replies)
Discussion started by: Mid Ocean
3 Replies

10. Shell Programming and Scripting

Shell Variables passed to awk to return certain rows

Hi Forum. I have the following test.txt file and need to extract certain rows based on "starting position", "length of string" and "string to search for": 1a2b3d 2a3c4d ..... My script accepts 3 parameters: (starting col pos, length to search for, string to search for) and would like to... (4 Replies)
Discussion started by: pchang
4 Replies
XML::Easy::Classify(3pm)				User Contributed Perl Documentation				  XML::Easy::Classify(3pm)

NAME
XML::Easy::Classify - classification of XML-related items SYNOPSIS
use XML::Easy::Classify qw( is_xml_name check_xml_name is_xml_encname check_xml_encname is_xml_chardata check_xml_chardata is_xml_attributes check_xml_attributes is_xml_content_object check_xml_content_object is_xml_content_twine check_xml_content_twine is_xml_content check_xml_content is_xml_element check_xml_element ); if(is_xml_name($arg)) { ... check_xml_name($arg); if(is_xml_encname($arg)) { ... check_xml_encname($arg); if(is_xml_chardata($arg)) { ... check_xml_chardata($arg); if(is_xml_attributes($arg)) { ... check_xml_attributes($arg); if(is_xml_content_object($arg)) { ... check_xml_content_object($arg); if(is_xml_content_twine($arg)) { ... check_xml_content_twine($arg); if(is_xml_content($arg)) { ... check_xml_content($arg); if(is_xml_element($arg)) { ... check_xml_element($arg); DESCRIPTION
This module provides various type-testing functions, relating to data types used in the XML::Easy ensemble. These are mainly intended to be used to enforce validity of data being processed by XML-related functions. There are two flavours of function in this module. Functions of the first flavour only provide type classification, to allow code to discriminate between argument types. Functions of the second flavour package up the most common type of type discrimination: checking that an argument is of an expected type. The functions come in matched pairs. FUNCTIONS
Each of these functions takes one scalar argument (ARG) to be tested. Any scalar value is acceptable for the argument to be tested. Each "is_" function returns a simple truth value result, which is true iff ARG is of the type being checked for. Each "check_" function will return normally if the argument is of the type being checked for, or will "die" if it is not. is_xml_name(ARG) check_xml_name(ARG) Check whether ARG is a plain string satisfying the XML name syntax. (Such names are used to identify element types, attributes, entities, and other things in XML.) is_xml_encname(ARG) check_xml_encname(ARG) Check whether ARG is a plain string satisfying the XML character encoding name syntax. is_xml_chardata(ARG) check_xml_chardata(ARG) Check whether ARG is a plain string consisting of a sequence of characters that are acceptable to XML. Such a string is valid as data in an XML element (where it may be intermingled with subelements) or as the value of an element attribute. is_xml_attributes(ARG) check_xml_attributes(ARG) Check whether ARG is a reference to a hash that is well-formed as an XML element attribute set. To be well-formed, each key in the hash must be an XML name string, and each value must be an XML character data string. is_xml_content_object(ARG) check_xml_content_object(ARG) Check whether ARG is a reference to an XML::Easy::Content object, and thus represents a chunk of XML content. is_xml_content_twine(ARG) check_xml_content_twine(ARG) Check whether ARG is a reference to a twine array (see "Twine" in XML::Easy::NodeBasics), and thus represents a chunk of XML content. is_xml_content_array(ARG) Deprecated alias for "is_xml_content_twine". is_xml_content(ARG) check_xml_content(ARG) Check whether ARG is a reference to either an XML::Easy::Content object or a twine array (see "Twine" in XML::Easy::NodeBasics), and thus represents a chunk of XML content. is_xml_element(ARG) check_xml_element(ARG) Check whether ARG is a reference to an XML::Easy::Element object, and thus represents an XML element. SEE ALSO
Params::Classify, XML::Easy::NodeBasics AUTHOR
Andrew Main (Zefram) <zefram@fysh.org> COPYRIGHT
Copyright (C) 2009, 2010, 2011 Andrew Main (Zefram) <zefram@fysh.org> LICENSE
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.14.2 2011-11-16 XML::Easy::Classify(3pm)
All times are GMT -4. The time now is 04:39 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy