0

I have tried with the script but it does not work.

milenko@milenko-desktop:~/MTM$ script output.txt
Script started, file is output.txt

milenko@milenko-desktop:~/MTM$ wc -l output.txt
0 output.txt

There are more than 4000000 lines on my screen a s a result of execution of a C code.Just part of this

4194282 0.166666 2.35285e-06 -56.2841 -137.299 -129.386 4 0.974001
4194283 0.166666 2.2536e-06 -56.4712 -129.67 -131.872 4 0.577388
4194284 0.166666 2.33943e-06 -56.3089 -131.649 -132.051 4 0.693404
4194285 0.166666 2.40782e-06 -56.1838 -139.678 -129.377 4 0.702479
4194286 0.166666 2.61584e-06 -55.8239 -125.733 -128.783 4 0.585886
4194287 0.166666 2.60877e-06 -55.8356 -129.239 -127.815 4 0.773082
4194288 0.166666 2.71129e-06 -55.6682 -129.591 -127.553 4 0.796556
4194289 0.166666 2.89225e-06 -55.3876 -125.257 -127.627 4 0.815006
4194290 0.166666 2.84658e-06 -55.4568 -129.576 -127.566 4 0.557463
4194291 0.166666 2.71516e-06 -55.662 -129.31 -128.904 4 0.797976
4194292 0.166666 2.56104e-06 -55.9158 -127.996 -128.422 4 0.895766
4194293 0.166666 2.6007e-06 -55.8491 -128.079 -129.663 4 0.503785
4194294 0.166666 2.40808e-06 -56.1833 -140.025 -128.88 4 0.857429
4194295 0.166666 2.33237e-06 -56.322 -126.524 -130.575 4 0.410364
4194296 0.166666 2.46136e-06 -56.0883 -135.197 -130.224 4 0.833398
4194297 0.166666 2.48021e-06 -56.0551 -134.945 -131.935 4 0.856674
4194298 0.166666 2.43826e-06 -56.1292 -128.865 -128.875 4 0.490521
4194299 0.166666 2.45184e-06 -56.1051 -126.444 -129.16 4 0.935146
4194300 0.166667 2.51457e-06 -55.9954 -141.302 -130.337 4 0.745215
4194301 0.166667 2.47265e-06 -56.0684 -133.622 -131.74 4 0.541706
4194302 0.166667 2.45156e-06 -56.1056 -128.236 -128.832 4 0.503959
4194303 0.166667 2.54703e-06 -55.9397 -127.012 -127.581 4 1.10325
4194304 0.166667 2.55029e-06 -55.9341 -132.414 -127.012 4 0.475155

How to save this?

If I try script > output.txt

Script started, file is typescript
]0;milenko@milenko-desktop: ~/MTM[01;32mmilenko@milenko-desktop[00m:[01;34m~/MTM[00m$ exit
Script done, file is typescript

I have also tried

command | tee ~/outputfile.txt

But again

 wc -l outputfile.txt 
0 outputfile.txt

So this is not the right way.

  • 2
    The script command allows you to record the terminal session going forward - are you trying to save output that has already been displayed in your terminal? – steeldriver Dec 1 '16 at 14:51
  • @steeldriver Yes,exactly the output from the previous terminal session. – MikiBelavista Dec 1 '16 at 14:52
  • take a look here tecmint.com/… – Wissam Roujoulah Dec 1 '16 at 16:07
1

my little secret for when I need to capture both stdout and stderr is to use nohup. This is a good solution when you are only interested in output, not the interaction on screen as well.

The classic way to capture stdout (only) and display it on screen is to use the command tee

nohup script.sh | tee merged.out

And if only stdout is desired

script.sh | tee script.out

Here is a quick example using the command ls rather than script.sh

xx069:~ # nohup ls | tee merged.out
nohup: ignoring input and redirecting stderr to stdout
bin
inst-sys
merged.out
xx069:~ # cat merged.out
bin
inst-sys
merged.out

And, of course, redirection such as 2>&1 to combine stdout and stderr is also possible.

Mainly, I use script to capture the input and output on screen. When only the output is needed I use one of >, >>, 2>&1 >, tee, and tee -a - depending on the need. And nohup when I am lazy.

4

if You use script command:

script history_log.txt

then do what ever you want and when you finish type:

exit

if you mean the output of script then redirect stdout:

script.sh > output.txt
  • > redirect the stdout to any ware you want
  • 2> redirect the stderr
  • &> redirect both stdout and stderr
  • 3
    Just to avoid confusion. You are not taking about script command but rather a script file written by user like script.sh. – Kalavan Dec 1 '16 at 15:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.