2

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.

Adrian Heine
  • 4,051
  • 2
  • 30
  • 43
  • 3
    "will not accept"? WHAT is not accepting this? – Marc B Mar 27 '15 at 14:11
  • `cat -vet file1` Do you see `^M` at the end of each line? then `dos2unix file1` and try again (I'm not sure this is the issue, but a quick test and worth a try). Good luck. – shellter Mar 27 '15 at 14:46
  • There is nothing wrong with your command line, unless your implementation of `head` is really restrictive and wants to be `head -n 300` instead. Please include your actual error, so that we can help you understand what's wrong. – ghoti Apr 16 '15 at 19:56

2 Answers2

3

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?

JNevill
  • 46,980
  • 4
  • 38
  • 63
1

Try

head -n 300 < file1 > file2 
AlejandroVD
  • 1,576
  • 19
  • 22