1
1

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 5 years have passed since last update.

Bashのワンライナーでファイルから一行ずつ読み取ってフォルダを作成する

Last updated at Posted at 2018-07-06

ものすごく簡単ですけど、良く忘れるので備忘録として投稿。
testに作成したいフォルダ名を一行ずつ用意しておき、以下のコマンドを実行すればおk

awk '{print $1}' < test | xargs mkdir

$ ls
test

$ cat test
aaa
bbb
ccc

$ awk '{print $1}' < test | xargs mkdir

$ ls
aaa/  bbb/  ccc/  test

awkコマンドを使うのは、一行ずつ処理をさせたいから。

結果としては同じだけど、ファイルから一行ずつ読み取って、mkdirの引数に渡してコマンドを実行したい場合はxargs に -L 1 -tオプションを付ければよい。

λ awk '{print $1}' < test | xargs -L 1 -t mkdir
mkdir aaa
mkdir bbb
mkdir ccc

mkdir以外のコマンドを実行したい時のアイデアとして。

cat test でもいいんだけどね!!!

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?