1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

シェルスクリプトで、入力ファイルの2行目以降1行づつ扱いたい場合の備忘録

Posted at

シェルスクリプトで、以下のようなファイルの2行目以降1行づつ扱いたい場合、

test.csv
player
xxx
yyy
zzz

以下のようにヒアドキュメントを利用して入力する

https://e-words.jp/w/ヒアドキュメント.html
ヒアドキュメントとは、プログラミング言語などの機能の一つで、特殊な記号などを含む文字列リテラルをソースコード中に記述するための特別な記法のこと。

test.sh
#!/bin/bash
DATA=`cat test.csv | tail -n +2`
while read line
do
  echo $line
done << FILE
$DATA
FILE

実行結果

$ bash test.sh
xxx
yyy
zzz

参考

1
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?