Skip to content

Instantly share code, notes, and snippets.

@yuki2021
Last active November 13, 2023 05:13
Show Gist options
  • Save yuki2021/d8f1d19c1798f62ec7b361fc45745eb1 to your computer and use it in GitHub Desktop.
Save yuki2021/d8f1d19c1798f62ec7b361fc45745eb1 to your computer and use it in GitHub Desktop.
特定の文字が含まれてるファイルをディレクトリを回帰的に検索して、置換を行うシェルスクリプト
#!/bin/zsh
# testのディレクトリにlogger.dartのimport文を挿入するための使い捨てスクリプト
# 検索するコメント
search_string="// FirebaseSecureStorageをモック化"
# 挿入するインポート文
import_statement="import 'package:test_2023/constant/logger.dart';"
# 対象のディレクトリ内の全ての .dart ファイルを検索し、条件に合うものに対して処理を実行
grep -rl "$search_string" . --include=\*.dart | while read file
do
# ファイルの先頭にインポート文を挿入
gsed -i "1s#^#$import_statement\n#" "$file"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment