-3

我有两个 unl 文件.. sample.unl test.unl 如果我使用下面的 cat 命令,我的输出格式不正确。

{
cat sample.unl
echo
cat test.unl
}

.

store_nbr   country_code    date    
400  CA 2010-06-11 12:00:49

我希望输出正确对齐,如下所示..

store_nbr             country_code               date   
400                   CA                         2010-06-11 12:00:49

请帮助我..谢谢

4

1 回答 1

1

为此编写小python脚本:

$ cat format.py 
#!/usr/bin/python

import sys, re

with open(sys.argv[1], "r") as f:
    for line in f:
        print "%-20s %-20s %-20s" % tuple(re.split('\s+', line.rstrip('\n'), 2))

使用示例:

$ python format.py sample.unl
store_nbr            country_code         date                
400                  CA                   2010-06-11 12:00:49 
于 2012-07-11T18:18:07.173 回答