Languages and Scripting
Showing results for 
Search instead for 
Do you mean 

awk remove lines format to columns

SOLVED
Go to Solution
Highlighted
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
Acclaimed Contributor Acclaimed Contributor

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...
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!