LoginSignup
2
4

More than 5 years have passed since last update.

ファイル一行目をファイル名に変換するスクリプト

Last updated at Posted at 2015-03-09

ファイル一行目をファイル名に変換するスクリプト書いた

rename.sh
#!/bin/bash

for file in *.txt; do
  firstline=$(cat "$file" | head -1 | sed -e 's/\//-/g')
  [ -n "$firstline" ] && [ ! -e "${firstline}.txt" ] &&
  mv "$file" "${firstline}.txt"
done

何かおかしいところがあったら教えて下さい!

2
4
2

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
2
4