[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Calling a function with implementation in awk

From: uzibalqa
Subject: Calling a function with implementation in awk
Date: Sat, 18 Mar 2023 01:20:23 +0000

I have a number of bash functions that consist in their entirety of awk 
because I do not want a complicated mix of different languages in the same 

Thus I have the following

kuelseq ()
  awk -v ctp="$1" -v rst="$2" -v lseq="$3"  \
    'BEGIN { fm1="%s%s%s\n" ; fm2="%s\n"
        n = split(lseq, a, ",")
        for ( i=1 ; i<=n ; i++ ) laggr[a[i]] }

     { if (NR in laggr) printf(fm1, ctp, $0, rst)
       else printf(fm2, $0) }'

I want to call the function above from another bash function
called "kue", passing data either through redirection or a pipeline.

kue ()
 {  impl="REDR"
    if [[ "$impl" == "REDR" ]]; then      # Redirection
      kuelseq "$ctp" "$rst" "$lseq" < <(printf "%s\n" "$@")
    elif [[ "$impl" == "PIPL" ]]; then    # Pipeline
      printf '%s\n' "$@" | kuelseq "$ctp" "$rst" "$lseq"

I am under the impression that I am missing something in the function
"kuelseq", as I do require a way to pass the data supplied by "kue"
through "$@" into the function "kuelseq".

How should I handle the input problem to "kuelseq" ? 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]