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

シェルのリダイレクト時に元ファイル名を利用する方法

Posted at

概要

シェルでデータを加工する際に、bashのパラメータ展開を利用することで拡張子だけ変えたりすることが出来ます。

やり方

例えばcatで"temp.txt"を出力して、出力結果を"temp.csv"にしたい場合以下のようにします

parameter.sh
data = temp.txt
cat $data > "${data%.*}.csv"

逆に、拡張子は変えず、ファイル名だけを変えたい場合は
#*.
を使えばよいそうです。

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