help-bash
[Top][All Lists]
Advanced

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

Re: Calling a function with implementation in awk


From: uzibalqa
Subject: Re: Calling a function with implementation in awk
Date: Sat, 18 Mar 2023 02:07:53 +0000



------- Original Message -------
On Saturday, March 18th, 2023 at 1:59 PM, alex xmb ratchev <fxmbsw7@gmail.com> 
wrote:

Found things were being sent in rich format.  Changed things
so that things are now as text.


> On Sat, Mar 18, 2023, 2:21 AM uzibalqa <uzibalqa@proton.me> wrote:
 
I have a number of bash functions that consist in their entirety of awk 
commands, because I do not want a complicated mix of different languages in the 
same function.
 
 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"
   fi
 }
 
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]