[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Calling a function with implementation in awk
From: |
alex xmb ratchev |
Subject: |
Re: Calling a function with implementation in awk |
Date: |
Sat, 18 Mar 2023 03:00:08 +0100 |
On Sat, Mar 18, 2023, 2:59 AM alex xmb ratchev <fxmbsw7@gmail.com> wrote:
>
>
> 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,
>>
>
> u define those as vars
> awkfuncs=( 'code1 ..' 'code2 ..' .. )
> printf -v awkstr %s\\n "${awkfuncs[@]}"
>
awk "$awkstr" "$@"
gawk -e "$awkstr" -e 'other code' "$@"
because I do not want a complicated mix of different languages in the same
>> function.
>>
>> Thus I have the following
>>
>
> i get your pasted codes to 0 %
>
> 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" ?
>>
>>
>>