namsan
namsan

Reputation: 9

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

How can I print a value to specific line in Bash shell?
(For example, I would like to print a value up to the 10th line.)

Upvotes: 0

Views: 423

Answers (2)

Ted Lyngmo
Ted Lyngmo

Reputation: 117298

It's not specific to bash but you can use tput cup Y X to set the cursor position:

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

Upvotes: 3

Víctor Oriol
Víctor Oriol

Reputation: 566

Yo can try to show line numbers of the files, and grep it for the line:

$ 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

Upvotes: 0

Related Questions