我想问一下为什么这个简单的脚本会给出不同的缩进
如果我的方法有误,请提出正确的方法。 :)
数据文件:
Mr. James Adams General Manager
Mr. James Adams General Manager
Mr. James Carleo Branch Manager
Mr. James Cobb Branch Manager
Mr. James Collier Branch Manager
Mr. James K. Cross Sr.Vice
Mr. James Cummings Branch Manager
Mr. "James ""Jamie""" Dyer Branch
Mr. James (Danny) Farris Manager
Mr. James N. Martin General
Mr. James N. Martin General
Mr. James Ogden Branch Manager
Mr. James Wilson Branch Manager
脚本:
awk '{print $1,$2,$3,"\t",$4,$5}'
预期输出:
Mr. James Adams General Manager
Mr. James Adams General Manager
Mr. James Carleo Branch Manager
Mr. James Cobb Branch Manager
Mr. James Collier Branch Manager
Mr. James K. Cross Sr.Vice
Mr. James Cummings Branch Manager
Mr. "James ""Jamie""" Dyer Branch
Mr. James (Danny) Farris Manager
Mr. James N. Martin General
Mr. James N. Martin General
Mr. James Ogden Branch Manager
Mr. James Wilson Branch Manager
实际输出:
Mr. James Adams General Manager
Mr. James Adams General Manager
Mr. James Carleo Branch Manager
Mr. James Cobb Branch Manager
Mr. James Collier Branch Manager
Mr. James K. Cross Sr.Vice
Mr. James Cummings Branch Manager
Mr. "James ""Jamie""" Dyer Branch
Mr. James (Danny) Farris Manager
Mr. James N. Martin General
Mr. James N. Martin General
Mr. James Ogden Branch Manager
Mr. James Wilson Branch Manager
最佳答案
您可以使用 awk
中的 printf
来调整列宽等:
awk '{printf "%s %s %-20s %s %s\n",$1,$2,$3,$4,$5}' file
Mr. James Adams General Manager
Mr. James Adams General Manager
Mr. James Carleo Branch Manager
Mr. James Cobb Branch Manager
Mr. James Collier Branch Manager
Mr. James K. Cross Sr.Vice
Mr. James Cummings Branch Manager
Mr. "James ""Jamie""" Dyer Branch
Mr. James (Danny) Farris Manager
Mr. James N. Martin General
Mr. James N. Martin General
Mr. James Ogden Branch Manager
Mr. James Wilson Branch Manager
关于linux - shell 中的制表符给出不同的宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22681113/