I am looking for a way to print the current line number of the console output
I have tried doing some research on tput but I haven't find something that was suitable
What I am looking for is something where will show something like this:
Hello world
This is a fantastic world - 2
Another random string
A different random string
This is the last string and this is the line 5 of this output.
The important thing is that if in the console, before my command, I have ran some other string the line number should include those. Let's say that before that command I ran a different command that has included 10 lines, the number 2 should be 12 and the line 5 should be 15 and so on. I just need a way to find out in what line the output has been printed.
Any help will be much appreciated
UPDATE: I have been forwarded here How to get the cursor position in bash?
However I tried every method listed there and unfortunately while the code works fine I am not able to adapt it to my use. I am running different commands at the same time and the script won't wait for them to finish before moving to the next one (using & at the end of the command). Each of these commands should be able to save the current cursor position in order to print their results in the shell output. Unfortunately with all the code suggested in the other thread despite the row selected is different the output keeps appearing on the same line. Is there a way to save the output line number in a variable and then print something on the same line afterwards?
This was my original thread: Bash script, update output once command is ended