简体   繁体   中英

Linux find and replace Japanese string on filename

I need to find and replace a string in Japanese filenames in all subfolders.

I have tried all common find and replace commands but they do not seem to work with japanese characters.

Note: I do not want to remove all japanese characters only find and replace a certain string within the filename.

these are unicode characters, so you could find them with for example

find | grep -P '[\\x3041-\\x3096]' find | grep -P '[\\x3041-\\x3096]' (Hiragana)

find | grep -P '[\\x30A0-\\x30FF]' find | grep -P '[\\x30A0-\\x30FF]' (Katakana)

But you'd need to figure out the exact characters (unicode notation) you want to replace first.

However, it could be that your encoding is different. If you need to change encodings then use convmv , for example

convmv -f EUC-JP -t UTF-8 *

update. This script works for your example. I just copy/pasted the character.

SEARCH="名."  
REPLACE="_."

for x in *$CHAR*; do
 rename  "s/$SEARCH/$REPLACE/" $x
done

After trying many commands this worked:

find . -type f | xargs rename 's/textofind/newtext/g'

I did not have to type the unicode notation, I could type directly the japanese characters on the command line.

For users that just want to find and erase the string, you can use the command like this:

find . -type f | xargs rename 's/textofind//g'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM