The %-5s aligns the result as 5-character-wide columns; if this isn't enough, increase the number, or use %s (with a space) instead if you don't care about alignment.
选项1到3有多个空格的问题(但是很简单)。
That is the reason to develop options 4 and 5, which process multiple white spaces with no problem.
当然,如果选项4或5与 n=0一起使用,两者都将保留任何前导空格,因为 n=0意味着没有分裂。
I have a log where after $5 with an IP address can be more text or no text. I need everything from the IP address to the end of the line should there be anything after $5. In my case, this is actualy withn an awk program, not an awk oneliner so awk must solve the problem. When I try to remove the first 4 fields using the old nice looking and most upvoted but completely wrong answer:
echo " 7 27.10.16. Thu 11:57:18 37.244.182.218 one two three" | awk '{$1=$2=$3=$4=""; printf "[%s]\n", $0}'
它会吐出错误和无用的反应(我加了[]来证明) :
[ 37.244.182.218 one two three]
相反,如果列的宽度是固定的,直到需要切割点和 awk 为止,正确且相当简单的答案是:
echo " 7 27.10.16. Thu 11:57:18 37.244.182.218 one two three" | awk '{printf "[%s]\n", substr($0,28)}'