• Side-by-Side

    From Michael Sanders@porkchop@invalid.foo to comp.lang.awk on Fri Oct 24 14:28:42 2025
    From Newsgroup: comp.lang.awk

    #!/bin/sh

    <<'NOTES'

    Prints text blocks side-by-side

    Michael Sanders 2025

    You have...

    A.TXT

    Lorem ipsum dolor sit amet,
    consectetuer adipiscing elit.
    Nullam feugiat, turpis at
    pulvinar vulputate, erat libero
    tristique tellus, nec bibendum
    odio risus sit amet ante.

    B.TXT

    Aliquam erat volutpat. Nunc
    auctor. Mauris pretium quam et
    urna. Fusce nibh. Duis risus.
    Curabitur sagittis hendrerit
    ante. Aliquam erat volutpat.
    Vestibulum metus semper nulla.

    You want...

    Left Side Right Side

    Lorem ipsum dolor sit amet, Aliquam erat volutpat. Nunc
    consectetuer adipiscing elit. auctor. Mauris pretium quam et
    Nullam feugiat, turpis at urna. Fusce nibh. Duis risus.
    pulvinar vulputate, erat libero Curabitur sagittis hendrerit
    tristique tellus, nec bibendum ante. Aliquam erat volutpat.
    odio risus sit amet ante. Vestibulum metus semper nulla.

    NOTES

    str1="$(cat a.txt)"
    str2="$(cat b.txt)"

    clear

    awk -v gap=3 -v a="$str1" -v b="$str2" '
    BEGIN {
    # split strings into lines
    n1 = split(a, arr1, "\n")
    n2 = split(b, arr2, "\n")
    n = (n1 > n2 ? n1 : n2)

    # determine max width of 1st block
    max = 0
    for (q = 1; q <= n1; q++) {
    if (length(arr1[q]) > max) max = length(arr1[q])
    }

    # print side-by-side
    for(q = 1; q <= n; q++){
    s1 = (q <= n1 ? arr1[q] : "")
    s2 = (q <= n2 ? arr2[q] : "")
    # left-align 1st block with max, add uniform gap, print 2nd block
    printf "%-*s", max + gap, s1
    printf "%s\n", s2
    }
    }'

    echo

    # eof
    --
    :wq
    Mike Sanders
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Janis Papanagnou@janis_papanagnou+ng@hotmail.com to comp.lang.awk on Fri Oct 24 17:19:59 2025
    From Newsgroup: comp.lang.awk

    On 24.10.2025 16:28, Michael Sanders wrote:
    #!/bin/sh

    <<'NOTES'

    Prints text blocks side-by-side

    Michael Sanders 2025

    You have...

    A.TXT

    Lorem ipsum dolor sit amet,
    consectetuer adipiscing elit.
    Nullam feugiat, turpis at
    pulvinar vulputate, erat libero
    tristique tellus, nec bibendum
    odio risus sit amet ante.

    B.TXT

    Aliquam erat volutpat. Nunc
    auctor. Mauris pretium quam et
    urna. Fusce nibh. Duis risus.
    Curabitur sagittis hendrerit
    ante. Aliquam erat volutpat.
    Vestibulum metus semper nulla.

    You want...

    Left Side Right Side

    Lorem ipsum dolor sit amet, Aliquam erat volutpat. Nunc consectetuer adipiscing elit. auctor. Mauris pretium quam et
    Nullam feugiat, turpis at urna. Fusce nibh. Duis risus.
    pulvinar vulputate, erat libero Curabitur sagittis hendrerit
    tristique tellus, nec bibendum ante. Aliquam erat volutpat.
    odio risus sit amet ante. Vestibulum metus semper nulla.

    NOTES

    str1="$(cat a.txt)"
    str2="$(cat b.txt)"

    clear

    awk -v gap=3 -v a="$str1" -v b="$str2" '
    [...]'

    echo

    # eof


    Since you're obviously using a Unix shell you might be interested in

    $ paste a.txt b.txt

    as a simpler (though non-awk) solution.

    Janis

    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Michael Sanders@porkchop@invalid.foo to comp.lang.awk on Sat Oct 25 00:26:24 2025
    From Newsgroup: comp.lang.awk

    On Fri, 24 Oct 2025 17:19:59 +0200, Janis Papanagnou wrote:

    Since you're obviously using a Unix shell you might be interested in

    $ paste a.txt b.txt

    as a simpler (though non-awk) solution.

    Exactly right Janis =) Really just an exercise for me in wondering:

    'How does paste do that any how?'

    Now I know. I do wish Windows had a better *native* toolkit for
    these sorts of things. The real issue I have is a lack of printf
    from the command line in Windows. Awk (paste too) makes these sorts
    jobs trivial...

    Metrics <5 Years: 2020.10.23 to 2025.10.23>

    S&P500 Index 6738.44 +94.45%
    NASDAQ Index 22740.40 +96.92%
    DOW Index 46734.61 +64.93%
    PHLX Gold/Silver Index 285.58 +96.33%
    Bitcoin Spot Price $108.47K +738.03%
    --
    :wq
    Mike Sanders
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Janis Papanagnou@janis_papanagnou+ng@hotmail.com to comp.lang.awk on Sat Oct 25 03:03:38 2025
    From Newsgroup: comp.lang.awk

    On 25.10.2025 02:26, Michael Sanders wrote:

    [...] I do wish Windows had a better *native* toolkit for
    these sorts of things.

    Well, what shall I say to people that want to do such things
    but adhere to the Windows platform?

    You can of course install Cygwin to have access to the tools.

    Myself I got a clear preference once I saw and worked on a
    Unix system. And early access to books like Kernighan, Pike:
    "The UNIX Programming Environment" solidifies that. (Still
    worth reading for newbies, I think.)

    The real issue I have is a lack of printf
    from the command line in Windows.

    This is of course a Unix standard command. And if you can
    install some prominent Unix shell (or have it through Cygwin)
    you get it even as shell built-in.

    Awk (paste too) makes these sorts jobs trivial...

    (It's so amazing what you can do with the Unix tool chest!)

    Janis

    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From mack@mack@the-knife.org (Mack The Knife) to comp.lang.awk on Sat Oct 25 17:25:45 2025
    From Newsgroup: comp.lang.awk

    In article <10dh5ff$2viff$1@dont-email.me>,
    Michael Sanders <porkchop@invalid.foo> wrote:
    Now I know. I do wish Windows had a better *native* toolkit for
    these sorts of things. The real issue I have is a lack of printf
    from the command line in Windows. Awk (paste too) makes these sorts
    jobs trivial...

    Why not use WSL? (Windows Subsystem for Linux) where you get
    a real Linux shell and can run Linux binaries?
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Michael Sanders@porkchop@invalid.foo to comp.lang.awk on Sun Oct 26 07:50:40 2025
    From Newsgroup: comp.lang.awk

    On 25 Oct 2025 17:25:45 GMT, Mack The Knife wrote:

    Why not use WSL? (Windows Subsystem for Linux) where you get a real
    Linux shell and can run Linux binaries?

    Or even busybox for Windows, my personal/portable favorite:

    <https://frippery.org/busybox/>

    Now imagine for instance an older individual, owns a business,
    has invested allot of money into their tech, even has a small server.

    Now suggest you want to install 3rd party software...

    For me its non-issue, but for some it is. The inverse is true as well:
    Wine (Win Emulation) can never one up Win API.

    When in Rome, do as the Romans do.
    --
    :wq
    Mike Sanders
    --- Synchronet 3.21a-Linux NewsLink 1.2