Operating System - HP-UX
1747997 Members
4694 Online
108756 Solutions
New Discussion

to change a list of name (character or digits) from vertical to horizontal : Korn Shell

 
Hanry Zhou
Super Advisor

to change a list of name (character or digits) from vertical to horizontal : Korn Shell

I have a list of characters, and wanted to list them in horizontal format from vertical

 

for instance:
0c.07      -----> 0c.07 0a.12 ...
0a.12
...

 

Thank you!

none
3 REPLIES 3
Steven Schweda
Honored Contributor

Re: to change a list of name (character or digits) from vertical to horizontal : Korn Shell

> I have a list of characters, [...]

   Where "have" means what, exactly?  Separated by what, exactly?  One
space character?  Any number of white-space characters?  Other?

> and wanted to list them in horizontal format from vertical

   If "list them" means print one word per line to stdout, then one
might use "tr" to translate a space to a new-line.  For example (shown
here on a Mac):

pro3$ echo '0c.07 0a.12 0d.99' | tr ' ' '\n'
0c.07
0a.12
0d.99

   As usual, many things are possible, and details may matter.

Bill Hassell
Honored Contributor

Re: to change a list of name (character or digits) from vertical to horizontal : Korn Shell

As Steven mentioned, there is too little information here.

Is your list coming out of a program in stdout?
Or is the list in a file?
Is the one output line constrained to a maximum length?

The simplest method is to assign all the lines of numbers to a variable like this:

MYLIST=$(someProgramName  -options  params)
or
MYLIST=$(cat  SomeFileName)    ...or... MYLIST=$(< SomeFileName)

Then echo the variable:
echo $MYLIST

This will list all the numbers on one long line.

If you do this:
echo "$MYLIST"

then you will get the original one-number-per-line.

This will handle thousands of numbers on one line -- which may not be what you want. 
If you want the lines up to a certain length, then continued onto another line, use adjust like this:

echo $MYLIST | adjust -m 20

where -m 20 will start a new line at column 20 but not splitting any of the numbers at the end.



Bill Hassell, sysadmin
Dennis Handly
Acclaimed Contributor

Re: to change a list of name (character or digits) from vertical to horizontal : Korn Shell

If you want to limit the number of words per line, you can use "xargs -L number".