如何更改 AWK 中现有的打印行
当我执行以下行时,它会打印换行符中的单词。
awk 'BEGIN { print "line one\nline two\nline three" }'
如何在同一行中打印信息并刷新现有行?
例如,在执行循环时,它应该打印“一”,然后擦除该行并打印“二”,然后擦除该行并打印“三”等。您可以帮助我吗?
When i execute the following line, its prints the words in newline.
awk 'BEGIN { print "line one\nline two\nline three" }'
How can i print the info in the same line with flush the existing line?
For example, while executing the loop, it should print 'one' then wipe out the line and prints 'two' then wipe out the line and prints 'three' etc. can you please assist me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试将换行符
\n
更改为回车符\r
(这是否有效取决于您的终端设置)。哦,打印一堆尾随空白来擦除前一行,并使用printf
来避免print
总是自动出现\n
补充道。Try changing the newlines
\n
to carriage returns\r
(whether this works depends somewhat on your terminal settings). Oh, and print a bunch of trailing whitespace to wipe-out the previous line, and useprintf
to avoid the automatic\n
thatprint
always adds.通过“擦掉线路”,我假设您指的是马车return 可以使用
\r
转义序列来表示。例如:
“第一行”和“第二行”消失,因为它们已被删除并被“第三行”取代。
如果您希望文本在被擦除之前在一段时间内可见,则需要在每次打印之间插入延迟。
或者,使用循环
By "wipe out the line", I'm assuming you were referring to a carriage return which can be expressed using the
\r
escape sequence.For example:
"line one" and "line two" disappear as they have been wiped out and replaced by "line three".
If you wish to have the text visible for a certain time before it gets wiped out, you'll need to insert delays in between each print.
or, using a loop