What's the quickest, easiest way to read the first line only from a file? I know you can use file
, but in my case there's no point in wasting the time loading the whole file.
Preferably a one-liner.
What's the quickest, easiest way to read the first line only from a file? I know you can use file
, but in my case there's no point in wasting the time loading the whole file.
Preferably a one-liner.
Try this:
In one of my projects (qSandbox) I uses this approach to get the first line of a text file that I read anyways. I have my email templates are in a text files and the subject is in the first line.
fgets() returns " " which is a new line at the end,but using this code you will get first line without the lineBreak at the end :
If you don't mind reading in the entire file, then a one-liner would be:
:)