Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Linux's head selects a number of lines from the top of a file. Is there a command that selects a number of characters from the front of a line?

The use case behind the question is this: I want to head the first 10 lines from a file, but each of those 10 lines is extremely long and contain lots of white space, making it hard to discern where the line breaks are.

It would be much easier to get a general idea of the contents of the file if I could head the first 10 lines, but only view the first 50 characters of each line.

share|improve this question
up vote 6 down vote accepted

Try cut:

< bigfile cut -c 1-50 | head -n 10
share|improve this answer
redirection isn't needed here...cut -c 1-50 bigfile | head -n 10 is IMO more readable. – cas Oct 3 '12 at 22:34
I've been searching Google for about 3 hours for an answer to this question, it's to simple to create an actual question for it though. I would like to know which way is preferred between "-c 1-50" vs. "-c1-50" (based on the extra space between the argument and the value I suppose) would you happen to know which way is preferred? – Jacob Oct 25 '12 at 1:11
@Jacob Based on the POSIX argument and syntax guidelines and the POSIX spec for cut, I'd always include a space (it helps readability as well), although it seems that omitting the blank should still work. – jw013 Oct 25 '12 at 4:36
@jw013 thanks for your answer and the links, that's exactly what I was looking for. – Jacob Oct 25 '12 at 14:23

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.