4

I want to display at a specific line, e.g. line 4, from a text file in Terminal (I need this for character counts, using wc). I'm sure this is a simple problem but read -e 1 filename doesn't do it.

What can be used to accomplish this task?

  • Thanks. I expect that some form of cat or pr would also do it. I used:head -n 2 filename | tail -n 1 | wc -m That gives the number of characters + 1 (an end of line char?) <br/> – Spookpadda Aug 15 '15 at 12:19
7

You can use sed command:

sed -n '4p' YOUR_FILE

Or head/tail combination:

head -n 4 YOUR_FILE | tail -n 1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .