Skip to content

Instantly share code, notes, and snippets.

@0x1881
Last active June 13, 2024 13:39
Show Gist options
  • Save 0x1881/97c51fc96d2bff24056b1e9c87820b4c to your computer and use it in GitHub Desktop.
Save 0x1881/97c51fc96d2bff24056b1e9c87820b4c to your computer and use it in GitHub Desktop.
changer file and string
#!/bin/bash
echo "Hangi işlemi yapmak istiyorsunuz?"
echo "1 - Dosya içinde isim değişikliği."
echo "2 - Dosya ve dizin isim değişikliği."
echo "3 - Dosya indirme ve değiştirme."
read -p "Seçiminiz: " choice
if [ $choice -eq 1 ]; then
echo "Bu komut ile belirttiğiniz dizin altındaki bütün dosyalarda metinler X değerinden Y değerine değiştirilecektir."
read -p "Değiştirilecek dosyaların bulunduğu dizin: " path
read -p "Eski Kelime: " old_word
read -p "Yeni Kelime: " new_word
if [ -d "$path" ]; then
echo "Dizin bulundu. Değiştirme işlemi başlıyor..."
grep --exclude-dir={node_modules,vendor} -rl "$old_word" "$path" | xargs -I {} sed -i "s/$old_word/$new_word/g" {}
echo "Değiştirme işlemi tamamlandı."
else
echo "Hata: Dizin bulunamadı."
fi
elif [ $choice -eq 2 ]; then
echo "Bu komut ile belirttiğiniz dizin altındaki bütün dizin ya da dosya isimlerinde eşleşen metinler X değerinden Y değerine değiştirilecektir."
read -p "Değiştirilecek dosyaların bulunduğu dizin: " path
read -p "Eski Kelime: " old_word
read -p "Yeni Kelime: " new_word
if [ -d "$path" ]; then
echo "Dizin bulundu. Değiştirme işlemi başlıyor..."
find "$path" -depth -not -name "*node_modules*" -not -name "*vendor*" -name "*$old_word*" | while IFS= read -r file; do
new_name=$(echo "$file" | sed "s/$old_word/$new_word/g")
mv "$file" "$new_name"
done
echo "Değiştirme işlemi tamamlandı."
else
echo "Hata: Dizin bulunamadı."
fi
elif [ $choice -eq 3 ]; then
echo "Bu komut ile belirttiğiniz dosyalar, yine belirteceğiniz uzak bir dosya ile değiştirilecektir."
read -p "Değiştirilecek dosya tam yolu: " local_file
read -p "Uzak dosya adresi: " remote_file
wget "$remote_file" -O ~/new_file
echo "Yeni dosya indirildi. Değişiklik yapılıyor..."
mv ~/new_file "$local_file"
rm ~/new_file
echo "Değiştirme işlemi tamamlandı."
else
echo "Geçersiz seçim. Program sonlandırılıyor."
fi
#!/bin/bash
while getopts c:u:a:f:o:n:l:r:p: flag
do
case "${flag}" in
c) choice=${OPTARG};;
o) old_word=${OPTARG};;
n) new_word=${OPTARG};;
l) local_file=${OPTARG};;
r) remote_file=${OPTARG};;
p) path=${OPTARG};;
esac
done
if [ $choice -eq 1 ]; then
if [ -d "$path" ]; then
echo "Dizin bulundu. Değiştirme işlemi başlıyor..."
grep --exclude-dir={node_modules,vendor} -rl "$old_word" "$path" | xargs -I {} sed -i "s/$old_word/$new_word/g" {}
echo "Değiştirme işlemi tamamlandı."
else
echo "Hata: Dizin bulunamadı."
fi
elif [ $choice -eq 2 ]; then
if [ -d "$path" ]; then
echo "Dizin bulundu. Değiştirme işlemi başlıyor..."
find "$path" -depth -not -name "*node_modules*" -not -name "*vendor*" -name "*$old_word*" | while IFS= read -r file; do
new_name=$(echo "$file" | sed "s/$old_word/$new_word/g")
mv "$file" "$new_name"
done
echo "Değiştirme işlemi tamamlandı."
else
echo "Hata: Dizin bulunamadı."
fi
elif [ $choice -eq 3 ]; then
wget "$remote_file" -O ~/new_file
echo "Yeni dosya indirildi. Değişiklik yapılıyor..."
mv ~/new_file "$local_file"
echo "Değiştirme işlemi tamamlandı."
else
echo "Geçersiz seçim. Program sonlandırılıyor."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment