1

I want to save the output to file and at the same time, I also want to see the progress on the screen.

Basically tee is only working for a single line only. Is there any solution for this?

[user@linux ~]$ cat -n test.sh 
     1  echo line 1 | tee out.txt
     2  echo line 2 | tee out.txt
     3  echo line 3 | tee out.txt
     4  ls -lh out*
[user@linux ~]$ 

[user@linux ~]$ ./test.sh 
line 1
line 2
line 3
-rw-r--r-- 1 user user 7 Mar  7 11:58 out.txt?
[user@linux ~]$ 

[user@linux ~]$ cat out.txt^M 
line 3
[user@linux ~]$ 

[user@linux ~]$ cat out.txt
cat: out.txt: No such file or directory
[user@linux ~]$ 

What I want is something like this.

[user@linux ~]$ ./test.sh 
line 1
line 2
line 3
-rw-r--r-- 1 user user 7 Mar  7 11:58 out.txt
[user@linux ~]$ 

[user@linux ~]$ cat out.txt
line 1
line 2
line 3
-rw-r--r-- 1 user user 7 Mar  7 11:58 out.txt
[user@linux ~]$ 
  • Hi @that other guy, I've read that link. It's totally different –  Mar 07 '18 at 08:28
  • My bad. It was definitely still one of the issues though, and it's why you're getting `out.txt^M` instead of the filename you wanted. – that other guy Mar 07 '18 at 15:55
  • The main issue was to display output on screen (real time) and save it at the same time. This was resolved by creating another file to call the other one. If you see the example above, only the last line displayed on the screen. –  Mar 08 '18 at 03:40

1 Answers1

0

If you can add tee while execution it would do it. Something like

bash file.sh | tee OUT.txt

with this you don't have to call tee with every echo

Raja G
  • 5,973
  • 14
  • 49
  • 82
  • it works ... `[user@linux ~]$ cat run.sh ./test.sh | tee out.txt [user@linux ~]$ [user@linux ~]$ cat test.sh echo line 1 | tee out.txt echo line 2 | tee out.txt echo line 3 | tee out.txt ls -lh out* [user@linux ~]$ [user@linux ~]$ ./run.sh line 1 line 2 line 3 -rw-r--r-- 1 user user 7 Mar 7 16:32 out.txt [user@linux ~]$ [user@linux ~]$ cat out.txt line 1 line 2 line 3 -rw-r--r-- 1 user user 7 Mar 7 16:32 out.txt [user@linux ~]$ ` –  Mar 07 '18 at 08:34