Professional Web Applications Themes

How to list the first 10 lines error from executing command - UNIX Programming

In article <1673c1fd.0307291148.7fd25c2eposting.google.com >, John <johnwuyorku.ca> wrote: >Hello All > >I know this is a common question, but I didn't know how to search and >get its answer, say if the following command end up with lots lines of >error, > >javac file.java >javac find error:file.java error 1111 >file.java:error 22222... >.... > >how to let it just displaying the first 10 lines of error, something >like > >more a_file | head -10 #or >cat a_file | grep "myError" javac file.java 2>&1 | head -10 2>&1 means to redirect stderr to where stdout goes, and then you can use the familiar ...

  1. #1

    Default Re: How to list the first 10 lines error from executing command

    In article <1673c1fd.0307291148.7fd25c2eposting.google.com >,
    John <johnwuyorku.ca> wrote:
    >Hello All
    >
    >I know this is a common question, but I didn't know how to search and
    >get its answer, say if the following command end up with lots lines of
    >error,
    >
    >javac file.java
    >javac find error:file.java error 1111
    >file.java:error 22222...
    >....
    >
    >how to let it just displaying the first 10 lines of error, something
    >like
    >
    >more a_file | head -10 #or
    >cat a_file | grep "myError"
    javac file.java 2>&1 | head -10

    2>&1 means to redirect stderr to where stdout goes, and then you can use
    the familiar piping of stdout to post-process that.

    --
    Barry Margolin, [email]barry.margolinlevel3.com[/email]
    Level(3), Woburn, MA
    *** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
    Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
    Barry Margolin Guest

  2. #2

    Default Re: How to list the first 10 lines error from executing command

    [email]johnwuyorku.ca[/email] (John) writes:
    > Hello All
    >
    > I know this is a common question, but I didn't know how to search
    > and get its answer, say if the following command end up with lots
    > lines of error,
    >
    > javac file.java
    > javac find error:file.java error 1111
    > file.java:error 22222...
    > ....
    >
    > how to let it just displaying the first 10 lines of error, something
    > like
    >
    > more a_file | head -10 #or
    > cat a_file | grep "myError"
    Try

    javac file.java 2>&1 >/dev/null | head -10

    Joe
    Joe Halpin Guest

  3. #3

    Default Re: How to list the first 10 lines error from executing command


    "Joe Halpin" <jhalpinnortelnetworks.com_.nospam> wrote in message
    news:yxs7n0exm6zv.fsfnortelnetworks.com_.nospam.. .
    > Try
    >
    > javac file.java 2>&1 >/dev/null | head -10
    >
    > Joe
    Thanks, Joe

    In sh, it works, but I'm using tcsh and csh, it said that it was ambiguous
    redirect output, do you mind telling me again how to do it for tcsh, or csh?

    --
    Best Regards
    John


    JohnWu Guest

  4. #4

    Default Re: How to list the first 10 lines error from executing command

    On Wed, 30 Jul 2003 at 01:34 GMT, JohnWu wrote:
    >
    > "Joe Halpin" <jhalpinnortelnetworks.com_.nospam> wrote in message
    > news:yxs7n0exm6zv.fsfnortelnetworks.com_.nospam.. .
    >> Try
    >>
    >> javac file.java 2>&1 >/dev/null | head -10
    >
    > In sh, it works, but I'm using tcsh and csh, it said that it was ambiguous
    > redirect output, do you mind telling me again how to do it for tcsh, or csh?
    Redirection is one of the things that [t]csh doesn't handle well.

    Why don't you use a Bourne-type shell? [T]csh is not recommended
    for scripting.

    --
    Chris F.A. Johnson [url]http://cfaj.freeshell.org[/url]
    ================================================== =================
    My code (if any) in this post is copyright 2003, Chris F.A. Johnson
    and may be copied under the terms of the GNU General Public License
    Chris F.A. Johnson Guest

  5. #5

    Default Re: How to list the first 10 lines error from executing command


    "Chris F.A. Johnson" <c.f.a.johnsonrogers.com> wrote in message
    news:bg7ciq$lhnck$1ID-136730.news.uni-berlin.de...
    > Redirection is one of the things that [t]csh doesn't handle well.
    >
    > Why don't you use a Bourne-type shell? [T]csh is not recommended
    > for scripting.
    >
    Bourne Shell is better, I agree. The things to me are, my account's default
    shell is set to tcsh, and some of the commands linked to DB2 and other
    softwares only work in tcsh (guess this can be fixed).

    Anyway, the inconvenience for me to use Bourne Shell is that, I don't know
    how to set up or configure the environment, so that whenever login to my
    account in Solaris 5.8, the (Left and Right) arrows keys can display the
    command histroy,so that long command line can be issued by a Arrow key
    javac -classpath ..... file.java .....

    --
    Thanks
    John


    JohnWu Guest

  6. #6

    Default Re: How to list the first 10 lines error from executing command

    > You can't redirect stderr separate from stdout in csh, only both, like
    > this:
    >
    > javac file.java |& head -10
    > javac file.java |& more
    >
    > (man csh:
    > A simple command, or a set of simple commands separated by |
    > or |& characters, forms a pipeline. With |, the standard output
    > of the preceding command is redirected to the standard input of
    > the command that follows. With |&, both the standard error and
    > the standard output are redirected through the pipeline.
    > )
    >
    Thanks lots, that's what I wanted.
    One more thing regarding Bourne-sh, as asked in previous thread, in sh, how
    to set Arrow key to display history command, as in csh?
    --
    John
    Toronto


    JohnWu Guest

  7. #7

    Default Re: How to list the first 10 lines error from executing command

    "JohnWu" <johnwuyorku.ca> writes:
    > "Chris F.A. Johnson" <c.f.a.johnsonrogers.com> wrote in message
    > news:bg7ciq$lhnck$1ID-136730.news.uni-berlin.de...
    > > Redirection is one of the things that [t]csh doesn't handle well.
    > >
    > > Why don't you use a Bourne-type shell? [T]csh is not recommended
    > > for scripting.
    > >
    > Bourne Shell is better, I agree. The things to me are, my account's
    > default shell is set to tcsh, and some of the commands linked to DB2
    > and other softwares only work in tcsh (guess this can be fixed).
    >
    > Anyway, the inconvenience for me to use Bourne Shell is that, I
    > don't know how to set up or configure the environment, so that
    > whenever login to my account in Solaris 5.8, the (Left and Right)
    > arrows keys can display the command histroy,so that long command
    > line can be issued by a Arrow key javac -classpath ..... file.java
    If you use korn shell or bash you get (IMO) better command line recall
    and editing than with csh, and you can choose between vi and emacs
    editing modes.

    Take a look at

    [url]http://www.faqs.org/faqs/unix-faq/shell/shell-differences/[/url]

    Joe
    Joe Halpin Guest

  8. #8

    Default Re: How to list the first 10 lines error from executing command

    * "JohnWu" <johnwuyorku.ca>
    | One more thing regarding Bourne-sh, as asked in previous thread, in
    | sh, how to set Arrow key to display history command, as in csh?

    You can't do this neither in plain sh, nor in regular csh. You can do
    this in tcsh (enhanced version of csh) and in bash (enhanced GNU
    version of sh). Other shells may have other editing features (such as
    ksh's vi mode).

    R'
    Ralf Fassel Guest

  9. #9

    Default Re: How to list the first 10 lines error from executing command

    Ralf Fassel <ralfixxgmx.de> writes:
    > * "JohnWu" <johnwuyorku.ca>
    > | One more thing regarding Bourne-sh, as asked in previous thread, in
    > | sh, how to set Arrow key to display history command, as in csh?
    >
    > You can't do this neither in plain sh, nor in regular csh. You can do
    > this in tcsh (enhanced version of csh) and in bash (enhanced GNU
    > version of sh). Other shells may have other editing features (such as
    > ksh's vi mode).
    In emacs mode (at least - I don't use vi mode) ksh and bash can both
    use the arrow keys for command line recall. ksh needs some aliases
    setup, but bash seems to do it builtin.

    Joe
    joe@invalid.address Guest

Similar Threads

  1. List with Grid Lines
    By dzlmbq in forum Macromedia Flex General Discussion
    Replies: 2
    Last Post: May 12th, 09:02 PM
  2. Error executing child request for error.aspx
    By Shridhar in forum ASP.NET Building Controls
    Replies: 2
    Last Post: April 19th, 09:30 AM
  3. command list
    By Manno Bult in forum Macromedia Director Lingo
    Replies: 0
    Last Post: September 3rd, 09:14 PM
  4. executing a shell command within a function
    By Svlyp in forum PHP Development
    Replies: 0
    Last Post: August 16th, 12:19 AM
  5. executing "DB2 load command" from perl return errors
    By Ian D. Bjorhovde in forum PERL Miscellaneous
    Replies: 5
    Last Post: July 2nd, 02:17 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139