Simpler Navigation for Servers and Operating Systems
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
Languages and Scripting
cancel
Showing results for 
Search instead for 
Did you mean: 

awk remove lines format to columns

SOLVED
Go to solution
Ratzie
Super Advisor

awk remove lines format to columns

I am trying to write a ksh script that pulls data to a file, have it working no problem.
format of file.

13-JAN-09-22:17:00
12-JAN-09-07:13:07
NULL
NULL
13-JAN-09-21:08:04

Some times the NULL values will also be dates.

So I want to take this and join lines and format to columns.

Here is what I have working:
cat test.1| tr '\n' '\t'|awk '{print $1, $2, $3, $4, $5}'>>monitor.log

what I would like to do is have each variable line up at certain column.

Because right now the file looks fine:
13-JAN-09-22:16:38 12-JAN-09-07:12:57 NULL NULL 13-JAN-09-21:08:04
13-JAN-09-22:17:00 12-JAN-09-07:13:07 NULL NULL 13-JAN-09-21:08:04

But if I get an entry in $3 $4, nothing will line up anymore.


So how do I format $1 to start at 1, $2 start at 15 $3 start at the next 15... on so on.


2 REPLIES
James R. Ferguson
Acclaimed Contributor
Solution

Re: awk remove lines format to columns

Hi:

> So how do I format $1 to start at 1, $2 start at 15 $3 start at the next 15... on so on.

You use formatted print statements:

# cat test.1|tr '\n' '\t'|awk '{printf "%-15s %-15s %-15s %-15s %-15s\n",$1,$2,$3,$4,$5}'

This lef-justifies fields in units of 15-characters. See the manpages for 'printf'.

Regards!

...JRF...
Highlighted
Ratzie
Super Advisor

Re: awk remove lines format to columns

Works PERFECT!
I have been fiddling with printf and nothing but errors.
Put a question in and I got a reply with 10 minutes!