Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7960965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:54:02+00:00 2026-06-04T04:54:02+00:00

Is there a *nix command that formats input (delimited by newlines) so that only

  • 0

Is there a *nix command that formats input (delimited by newlines) so that only a specific max number of elements appear per line? For example:

$ yes x | head -10 | command 4
x x x x
x x x x
x x

I wrote a quick bash script (shown below) that performs this task, but it seems long and probably inefficient. Is there a better way to do this?

#!/bin/sh

if [ -z "$1" -o -z "$2" ]; then
        echo Usage `basename $0` {rows} {columns}
        exit 1
fi

ROWS=$1
COLS=$2

input=$(yes x | head -${ROWS})
lines=()
i=0
j=0
eol=0

for x in ${input[*]}
do
        lines[$i]="${lines[$i]} $x"
        j=`expr $j + 1`
        eol=0
        if [ $j -ge ${COLS} ]; then
                echo lines[$i] = ${lines[$i]}
                i=`expr $i + 1`
                j=0
                eol=1
        fi
done

if [ ${eol} -eq 0 ]; then
        echo lines[$i] = ${lines[$i]}
fi
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T04:54:03+00:00Added an answer on June 4, 2026 at 4:54 am
    printf '%-10s%-10s%-10s%s\n' $(command | command)
    

    printf will consume the number of arguments specified in the format string at a time and continue until they’re all consumed.

    Demonstration:

    $ printf '%-10s%-10s%-10s%s\n' $(yes x | head -n 10)
    x         x         x         x
    x         x         x         x
    x         x
    $ printf '%-10s%-10s%-10s%s\n' $(<speech)
    now       is        the       time
    for       all       good      men
    to        come      to        the
    aid       of        their     country
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any application/project that provides you with a command line SQL client that
Is there a way to simulate the *nix tail command on the Windows command
Are there any tools for windows like that *nix world has? I am looking
Is there there an open source command line tool that will convert xls/xlsx to
There's a dropdown displaying 1-10 from where the user selects the number of textboxes
Just now I found that static libraries in *nix systems, in other words *.a
Is there a difference between compiling projects in *nix environments and MS Visual C++?
Are there any ways to debug python scripts not leaving vim in *nix systems
Is there any lightweight *nix OS dedicated for programming purposes? Actually, I have a
Quick question, Is there a way to pipe a command into another command via

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.