0
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 > Brace Expansionで日付のダミーファイルを作る | ファイル名失敗時: MinGW32でファイルを消す

Last updated at Posted at 2017-10-17
動作環境
Windows 7 Pro (32bit)
SmartGit Version 17.0.4 #10132
SmartGit付属のMinGW32
grep (GNU grep) 2.24
head (GNU coreutils) 8.25

X_20170131.csv
のようなファイルをテスト用に作りたい。

参考

Brace Expansionが便利
by @__nagameeさん

v0.1

code

mkdmy_datetimefiles_171017_exec
#!/usr/bin/env bash

# on MinGW32

# X: prefix
filename=$(echo "X_"{2017..2017}{01..03}{01..31}".csv")
touch $filename
echo $filename

SmartGitからOpen Git-Shellして(MinGW32を起動し)、起動のフォルダにスクリプトを置いて実行する。

$ bash mkdmy_datetimefiles_171017_exec X_20170101.csv X_20170102.csv X_20170103.csv X_20170104.csv X_20170105.csv X_20170106.csv X_20170107.csv X_20170108.csv X_20170109.csv X_20170110.csv X_20170111.csv X_20170112.csv X_20170113.csv X_20170114.csv X_20170115.csv X_20170116.csv X_20170117.csv X_20170118.csv X_20170119.csv X_20170120.csv X_20170121.csv X_20170122.csv X_20170123.csv X_20170124.csv X_20170125.csv X_20170126.csv X_20170127.csv X_20170128.csv X_20170129.csv X_20170130.csv X_20170131.csv X_20170201.csv X_20170202.csv X_20170203.csv X_20170204.csv X_20170205.csv X_20170206.csv X_20170207.csv X_20170208.csv X_20170209.csv X_20170210.csv X_20170211.csv X_20170212.csv X_20170213.csv X_20170214.csv X_20170215.csv X_20170216.csv X_20170217.csv X_20170218.csv X_20170219.csv X_20170220.csv X_20170221.csv X_20170222.csv X_20170223.csv X_20170224.csv X_20170225.csv X_20170226.csv X_20170227.csv X_20170228.csv X_20170229.csv X_20170230.csv X_20170231.csv X_20170301.csv X_20170302.csv X_20170303.csv X_20170304.csv X_20170305.csv X_20170306.csv X_20170307.csv X_20170308.csv X_20170309.csv X_20170310.csv X_20170311.csv X_20170312.csv X_20170313.csv X_20170314.csv X_20170315.csv X_20170316.csv X_20170317.csv X_20170318.csv X_20170319.csv X_20170320.csv X_20170321.csv X_20170322.csv X_20170323.csv X_20170324.csv X_20170325.csv X_20170326.csv X_20170327.csv X_20170328.csv X_20170329.csv X_20170330.csv X_20170331.csv

そのフォルダに2017年1月から2017年3月のファイルが生成される。
(2月31日とかできるが、今回の目的のためには看過する。I'll let the mistakes go)。

補足

なお、スクリプトを間違えておかしなファイル名のファイルが生成されると、Explorerから消せなくなる場合がある。
その場合は、MinGW32からrmで消すことができる。
参考: @muroさんに以前、教えていただきました

rm '%1s_%s%02d%02d.csv '

(rmでシングルクォーテーションから始めて、Tab補完でファイル名入力)

v0.2

prefixを増やした。

mkdmy_datetimefiles_171017_exec
#!/usr/bin/env bash

# on MinGW32

# v0.2 Oct. 17, 2017
#   - add prefixes "Y" and "Z"
# v0.1 Oct. 17, 2017
#   - loop with year, month, and day with prefix "X"

# X: prefix
filename=$(echo {X..Z}"_"{2017..2017}{01..03}{01..31}".csv")
touch $filename
echo $filename
0
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
0
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?