在 shell 中,如何使空格长度与菜单上的单词长度相等?
我尝试获取最长字符串的长度,然后通过最长字符串+1 创建每列长度...而且我在这方面遇到了很多问题,我想阅读有关此主题的更多信息。
会是awk
还是grep
?
menuNAME menuNAME2 menuNAME3
word word2 THISwordisLongest
THISwordisLongest word wordLONG
wordLONG THISwordisLongest word
预期输出:
menuNAME menuNAME2 menuNAME3
word wordLONG THISwordisLongest
THISwordisLongest word wordLONG
wordLONG THISwordisLongest word
答案1
您可以使用柱子:
$ column -t < file
menuNAME menuNAME2 menuNAME3
word word2 THISwordisLongest
THISwordisLongest word wordLONG
wordLONG THISwordisLongest word