how to program in shell to get a part of a file by line number

This is a discussion on how to program in shell to get a part of a file by line number within the Tech Board forums, part of the Community Boards category; Hello everyone, I am wondering how to program in shell to get a part of a file by indicated (input) ...

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    1,579

    how to program in shell to get a part of a file by line number

    Hello everyone,


    I am wondering how to program in shell to get a part of a file by indicated (input) line number, for example, get from line 100 to line 200 in a specific file.

    What command(s) should I use?


    thanks in advance,
    George

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,592
    Code:
    $ # first 10 lines
    $ head foo.c
    void f1 ( void **p ) {
        *p = 0;
    }
    
    void f2 ( ) {
        int *p1;
        void *p2;
        f1( &p1 );
        f1( &p2 );
    }
    
    $ # a subset of lines
    $ sed -n '7,9p' foo.c
        void *p2;
        f1( &p1 );
        f1( &p2 );
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Cool, thank you Salem!


    Quote Originally Posted by Salem
    Code:
    $ # first 10 lines
    $ head foo.c
    void f1 ( void **p ) {
        *p = 0;
    }
    
    void f2 ( ) {
        int *p1;
        void *p2;
        f1( &p1 );
        f1( &p2 );
    }
    
    $ # a subset of lines
    $ sed -n '7,9p' foo.c
        void *p2;
        f1( &p1 );
        f1( &p2 );

    regards,
    George

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie homework help
    By fossage in forum C Programming
    Replies: 3
    Last Post: 04-30-2009, 04:27 PM
  2. Replies: 3
    Last Post: 03-04-2005, 01:46 PM
  3. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 09:46 AM
  4. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21