# How do I use fastercsv to just read the header row and not the whole file?

**URL:** <https://www.ruby-forum.com/t/how-do-i-use-fastercsv-to-just-read-the-header-row-and-not-the-whole-file/173254>\
**Category:** Rails\
**Created:** [August 5, 2009, 6:18pm UTC](https://www.ruby-forum.com/t/how-do-i-use-fastercsv-to-just-read-the-header-row-and-not-the-whole-file/173254 "2009-08-05T18:18:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sultan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/aeb1de/32.png) [@sultan](https://www.ruby-forum.com/u/sultan)\
**Post date:** [August 5, 2009, 6:18pm UTC](https://www.ruby-forum.com/t/how-do-i-use-fastercsv-to-just-read-the-header-row-and-not-the-whole-file/173254/1 "2009-08-05T18:18:33Z")

</div>

How do I use fastercsv to just read the header row and not the whole  
file?

I need to read the header row first and not the whole csv file  
initially in the web application so I can map the input csv columns to  
the db columns. Once the mapping is complete, a rake task will than  
process the whole file. I don’t want to read the whole file to save  
processing time.

How do I just read the header row only? I am assuming this would give  
me an array “row” and row[0] will be the first column header, row[1]  
the second column header, and so on.

Any help would be appreciated.

---

<div class="post-metadata">

**Author:** ![sultan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/aeb1de/32.png) [@sultan](https://www.ruby-forum.com/u/sultan)\
**Post date:** [August 5, 2009, 7:05pm UTC](https://www.ruby-forum.com/t/how-do-i-use-fastercsv-to-just-read-the-header-row-and-not-the-whole-file/173254/2 "2009-08-05T19:05:57Z")

</div>

On Aug 5, 2009, at 9:17 AM, sultan wrote:

> How do I use fastercsv to just read the header row and not the whole  
> file?

Open the file using FasterCSV’s new method, read one line, and bail out.
