繁体   English   中英

如何在 Bash shell 中的特定行中设置 output 的值?

[英]How can I output a value to a specific line in Bash shell?

如何将值打印到 Bash shell 中的特定行?
(例如,我想打印一个直到第 10 行的值。)

它不是特定于bash但您可以使用tput cup YX设置 cursor position:

tput sc         # save cursor position
tput cup 10 0
echo -n "hello"
tput rc         # restore cursor position

哟可以尝试显示文件的行号,并 grep 它为该行:

$ cat test 
A
B
C
$ cat test -n |grep ^"     2"
     2  B

$ cat test2
A
B
C
D
E
F
$ cat test2 -n |grep ^"     4"
     4  D

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM