- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Colunm formating
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2004 03:39 AM
01-05-2004 03:39 AM
Pls a *easier* way to echo a $VAR content in n colummns, i.e:
VAR="01 02 03 04 05 06 07 08 09 10 11"
I need echo $VAR up to four columns format:
01 02 03 04
05 06 07 08
09 10 11
BR,
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2004 03:47 AM
01-05-2004 03:47 AM
Re: Colunm formating
$ echo $VAR
1 2 3 4 5 6 7 8 9 10
$ echo $VAR | cut -f 1-3 -d\ 1-3
1 2 3
repeat "cut" as necessary to obtain the desidered output.
HTH,
Massimo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2004 03:52 AM
01-05-2004 03:52 AM
Re: Colunm formating
echo $VAR | awk -f useme.awk
Create a file called useme.awk which contains a SINGLE LINE (you may have to join lines after you cut and paste) that has this in it:
{for (idx1=1;idx1<=NF;idx1++) { printf ("%3s",$idx1); if ((idx1%4==0)||(idx1==NF
)) {printf ("\n");} } }
Note, the "3s" is making columns three spaces wide. If you want it to just have the columns be the width of your data then take out the "3". If you want the data columns wider then change the "3" to whatever width column you want.
Best regards,
Kent M. Ostby
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2004 03:52 AM
01-05-2004 03:52 AM
Re: Colunm formating
I need it in a single sweep.
BR,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2004 04:01 AM
01-05-2004 04:01 AM
Solution#!/usr/bin/sh
VAR="01 02 03 04 05 06 07 08 09 10 11"
set ${VAR}
while [[ ${#} -gt 0 ]]
do
typeset -i10 KNT=0
while [[ ${KNT} -lt 4 && ${#} -gt 0 ]]
do
echo "${1}\t\c"
shift
((KNT += 1))
done
echo
done
You probably would want to make a function out of this to call it with multiple variables.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2004 04:17 AM
01-05-2004 04:17 AM
Re: Colunm formating
e.g.
suppose you have only two digit wide columns,
how about something like this
$ var="12 43 28 29 23 21 38 21 93 21 29 29 39 29"
$ echo $var|fold -w 12
12 43 28 29
23 21 38 21
93 21 29 29
39 29
$
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2004 04:41 AM
01-05-2004 04:41 AM
Re: Colunm formating
echo $VAR | xargs -n4 echo
Just specify number of columns on -n parameter.
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-06-2004 07:14 PM
01-06-2004 07:14 PM
Re: Colunm formating
perl -e '$_=$ENV{"var"}; s/(\S+\s+\S+\s+\S+\s+\S+)\s+/$1\n/g; print "$_\n"'
or similar to the awk solution is:
echo $var | perl -e 'foreach $w (split(/ /,<>)){$s=(++$i % 4)?" ":"\n"; print "$w$s"}'
Or...
export $var
perl -e 'foreach $w (split (/ /,$ENV{"var"})) {$s=(++$i % 4)?" ":"\n"; print "$w$s"}'
I tried it in sed, but inserting a newline is too ugly for my taste for lack of a \n.
You have to use multiple lines. Some like
echo $var | sed -e "s/ /\\
/4" -e "s/ /\\
/7" -e "s/ /\\
/10"
Or very ugly with a post-translated helper character "q":
echo $var | sed -e "s/ /q/4" -e "s/ /q/7" -e "s/ /q/10" | tr q \\012
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-06-2004 07:29 PM
01-06-2004 07:29 PM
Re: Colunm formating
print $(echo $VAR | sed 's|\([^ ]* [^ ]* [^ ]* [^ ]*\) |\1\\n|g')
The sed command will replace every fourth space to '\n' which will be interpretted by print as a newline...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2004 02:10 AM
01-07-2004 02:10 AM