Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

I have 2000 txt files that I need to read the first line of (it should contain a person's name).

Ideally I would have a spreadsheet/csv with

share|improve this question
What operating systems do you have available? I think something like this will be much easier on linux or OS X than windows. – Darth Android Jun 22 '12 at 14:17
I agree, a bash script could probably handle this quite nicely. – Sion Jun 22 '12 at 14:22
up vote 3 down vote accepted

Under Windows, you can do this with a batch file:

@echo off
setlocal enabledelayedexpansion

set OUTPUT=names.csv
del %OUTPUT% > nul 2>&1

for %%f in (*.txt) do (
    set /p NAME=< %%f
    echo %%f,!NAME! >> %OUTPUT%


If you want the filename without the extension, change the for loop to this:

for %%f in (*.txt) do (
    set /p NAME=< %%f
    set INPUT=%%f
    echo !INPUT:~0,-4!, !NAME! >> %OUTPUT%
share|improve this answer

The best I came up with was

$ perl -e 'for(@ARGV){open($f,"<",$_);print"$_,",scalar<$f>}' *.txt

Perl works on Windows as well as Unix,Linux,etc - but you may need to install it first.

share|improve this answer
awesome, thanks guys!! – Joldfield101 Jun 25 '12 at 9:31

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.