help-gawk
[Top][All Lists]
Advanced

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

Re: Use variable from BEGIN as input to remaining program


From: Davide Brini
Subject: Re: Use variable from BEGIN as input to remaining program
Date: Wed, 6 Sep 2023 16:40:57 +0200

On Wed, 06 Sep 2023 12:14:26 +0000, port19 <port19@port19.xyz> wrote:

> In my limited research I did not manage to find ways to define records in
> BEGIN.
>
> Is it possible to use output retrieved in BEGIN as input for the rest of
> the program? If yes, how so?
> If not, how would you proceed?

Well I don't know much about the context, but for sure you can save
whatever you read in BEGIN into a variable or array, and that will be
available in the rest of the program. Stupid example:

awk '
  BEGIN{
    cmd = "ls /"
    i = 0
    while ((cmd | getline line) > 0)
      out[++i] = line
    close(cmd)
  }

  {
    # here "out" is visible
    print $0, out[1], out[2]
  }' <<< hello
hello bin boot

Or I'm not getting what you're trying to do.

--
D.



reply via email to

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