Skip to content

Instantly share code, notes, and snippets.

@He1my
Created May 8, 2022 07:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save He1my/e48f4e6d861a5a0706ae1058ad620c52 to your computer and use it in GitHub Desktop.
Save He1my/e48f4e6d861a5a0706ae1058ad620c52 to your computer and use it in GitHub Desktop.
#create a list of all files execluding directories
find ./ru -type f > files_ru.txt
#extract a list of untique words from files_ru.txt [because the file list is too large to translate using google trandslate]
grep -o -E '\w+' ./files.txt | sort -u -f > words_ru.txt
#moves files and creates missing parent directories, add to the end of ~/.bashrc
function mvp ()
{
dir="$2" # Include a / at the end to indicate directory (not filename)
tmp="$2"; tmp="${tmp: -1}"
[ "$tmp" != "/" ] && dir="$(dirname "$2")"
[ -a "$dir" ] ||
mkdir -p "$dir" &&
mv "$@"
}
#translate words_ru.txt to words_en.txt using google translate
#replace any spaces in the word files by an underscore
#combine both worlds_ru.txt and words_en.txt into a single file words_dict.txt
paste words_ru.txt words_en.txt > words_dict.txt
#create a sed script from the dict file
cat words_dict.txt | awk '{ printf("s/%s/%s/g\n", $1, $2); }' > sed_script
#use sed to replace the words in files_ru.txt
sed -f ./sed_script files_ru.txt > files_en.txt
Other useful commands:
=====================
# create a stored files list by depth
find . -type f -printf "%d %p\n"|sort -n|perl -pe 's/^\d+\s//;' > files_sorted.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment