LoginSignup
1
3

More than 5 years have passed since last update.

BATファイルで、テキストファイルの1行目だけを取り出す方法

Posted at

こんなファイルがあって

a.txt
aaa aa
bbb bb
ccc

このファイルから1行目だけを取り出したい(head -1したい)というときのやり方。

test.bat]
@echo off

for /f "usebackq tokens=*" %%a in (a.txt) do @set HEAD=%%a&goto :exit_for
:exit_for

echo %HEAD%
実行結果
aaa aa
1
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3