Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing output in columes

Status
Not open for further replies.

Larshg

Programmer
Mar 1, 2001
187
DK
Hi

I want to print a variable with spaces in front og it.

ex.
a=123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890

>echo $a - should loog like this
123456789012345678901234567890
123456789012345678901234567890
123456789012345678901234567890
>

all I want t do is to have a margin infront of the print - so that it won't use the first 5 spaces eventhou it shifts lines.

A nother thing is that I want only to ptint the first 30 caraters of $a

Thanks

/Lars
 
Try something like this:
Code:
echo $a | fold -w 30 | pr -o 5 -t

Hope This Help
PH.
 
thanks it works like a charm

How can I write something infront of it?
and how can I make a line brake right before the first 0


ex.
writing test infront of the first line, and making a line brake right before the first 0
test 123456789
012345678901234567890123456789
012345678901234567890123456789
012345678901234567890

/Lars
 
How about:

[tt]echo $a | nawk '{
i=match($0,"0")-1
print "test " substr($0,0,i)
i++
for (; i<length; i+=30) {
print &quot; &quot; substr($0,i,30)
}
}'[/tt]

You may need to use just awk or gawk depending on your environment.

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top