Search code examples
unixio-redirectionunix-head

Unix shell - copy first 300 lines to new file


I've been trying to solve this for days and nothings seems to work.

Copy first 300 lines of a file1 to a new file called file2. This file contains phone number information, already sorted by last name, which is the first field in each record.

 head -300 file1 > file2

should be the answer but it will not accept.

Any and all help appreciated.


Solution

  • You could use awk to do this:

    awk 'NR<=300' file1 > file2
    

    The real question is "Why isn't head working"... are you getting an error or something?