Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi all! We have been experiencing an issue on site where threads have been missing the latest postings. The platform host Vanilla are working on this issue. A workaround that has been used by some is to navigate back from 1 to 10+ pages to re-sync the thread and this will then show the latest posts. Thanks, Mike.
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Qutting command after so many lines of output

  • 13-12-2008 12:08am
    #1
    Moderators, Motoring & Transport Moderators Posts: 265 Mod ✭✭✭✭


    Hi guy's

    I'm currently writing a shell script that will run a particular command and print its output to a file.

    The only problem is that when I run the command in question it will print out the first 20 lines and then require the user to press RETURN to see the rest.
    I am however only interested in the first 20 lines so I was wondering if there was a way to quit the command once someone lines had been output.

    Eg.

    The script runs the command, reads the first 20 lines then quits the process rather than just sitting there waiting for user input

    Any help will be greatly appreciated


Comments

  • Registered Users, Registered Users 2 Posts: 9,579 ✭✭✭Webmonkey


    You could pipe it into head and redirect the output into a file?

    something like

    command | head - 20 > myfile.out - I'm only guessing this, still relatively new to linux unfort.

    Edit- Just noticed it probably the command that pauses automatically after 20 lines? - in that cause you will have to kill the process after the redirection. I amn't really sure how it will work to be honest, but worth a try


  • Closed Accounts Posts: 1,444 ✭✭✭Cantab.


    perl...

    Something like...

    'stopper.pl'
    #!/usr/bin/perl
    my $data=<CIN>;
    my $n=0;
    while($data)
    {
       if($data+=m/\n/)
       {
          $n=$n+1;
          if($n>=20)
          {
              print "Finished.\n";
              exit 0;
          }
       }
    }
    

    bash> ./myprog > perl stopper.pl

    Might be a bit long-winded. I'm sure awk could do it all in one line.


  • Registered Users, Registered Users 2 Posts: 37,485 ✭✭✭✭Khannie


    Cantab. wrote: »
    bash> ./myprog > perl stopper.pl

    That should be a | instead of a > or it'll overwrite your perl script. :)


Advertisement