1752785 Members
6102 Online
108789 Solutions
New Discussion

file content allignment

 
Intothenewworld
Advisor

file content allignment

I have a file , the content is as below

00 15 * 8 * /bin/chmod 755 /tmp
00 17,20 * 9 1 /bin/runcron

Now , I would like to allign it by space , the output is as the attachment file "output.txt" .

I have the below command , it is OK but it do the whole file , what I would like is to allign  the first 5 column ( the date and time column ) , can advise how can i do it ? thx


cat <file> | tr "[:space:]" "\t"

1 REPLY 1
Dennis Handly
Acclaimed Contributor

Re: file content alignment (crontab)

>what I would like is to align the first 5 columns (the date and time columns)

 

Perhaps using sed:

sed -e 's/^\([^ ]*\) \([^ ]*\) \([^ ]*\) \([^ ]*\) \([^ ]*\) \(.*$\)/\1\t\2\t\3\t\4\t\5\t\6/' file

(Where the "\t" should be replaced by a tab char.)

 

This assumes one space between each field.  It would be simple to handle multiple spaces.