#!/bin/bash# Linux Shell multifile content replace withsed# Disclaimer: # The source code is mainly the use of two (Chinese and English) with the same key-value pairs of JSON data, the HTML in the Chinese language # Automatic text substitution code. ## -- One- -Sunny Shenzhen Nanshan Ping Shan Village Zengjianfeng # get Chinese partsed-N"/\ "/P"SimpChinese.txt |grep-po-e"\ "\s?:\ S?. *"|grep-po-e": \s?. *"|grep-o-e"\".*\"">Simpchinese whileRead Chinese Do# Get the Chinese corresponding ID sectionID=`grep "$chinese"SimpChinese.txt |grep-o-e"^.*:"|grep-o-e"\".*\""|Head-N1' # Get the English part by ID 中文版=`grep "$id"English.txt |grep-po-e"\ "\s?:\ S?. *"|grep-po-e": \s?. *"|grep-o-e"\".*\""|Head-N1' # Remove double quotes Chinese=${chinese:1:-1} 中文版=${english:1:-1} # Remove the spaces on both sides #chinese=`Echo$chinese |sed "s/*$//g"|sed "s/^ *//g"' # Append to end of fileEcho "$chinese = = = $english">>Translate.txt Done<simpchinese# Some Chinese translators that are not in JSON key-value pairs join Translate.txtCatManualTranslate.txt >>Translate.txt whileRead ChEn Do# get Chinese, because some Chinese strings have'/'and deal with it primarily to deal with SED'/'the particularity of Chinese=`Echo$ChEn |grep-O"^.*==="|sed "s/===//"|sed "s/*$//g"|sed "s/^ *//g"|sed "s^\/^\\\\\\\\/^g"' 中文版=`Echo$ChEn |grep-O"===.*$"|sed "s/===//"|sed "s^\/^\\\\\\\\/^g"' # Match and modify the HTML page, [::! !??] is what is added based on the character of the string in HTMLsed-i-e"s/>\s*${chinese}[::!!??] \s*</>${english}</"rootfs/index.htmsed-i-e"s/>\s*${chinese}[::!!??] \s*</>${english}</"rootfs/set.htmsed-i-e"s/>\s*${chinese}[::!!??] \s*</>${english}</"Rootfs/html/*Done < translate.txt# section english.txt# {# "Right limit": "Set Right Limit", # "Set failed!": "Failed to Set!", # "OK" : "OK", # "Cancel": "Cancel", # "Set Path": "Storagepath", # "Set PTZ": "PTZ Settings", # "Auto-scan": "Scan", # "left Lim It ":" Set left Limit ", #" Add ":" Add ", #" Preset ":" Preset ", #" path ":" Path ", #" Browse ":" Choose ", #" Set succeeded! ":" Set successfully! ", #" delete ":" Delete "#}# section simpchinese.txt# {#" set path ":" Set Storage Path ", #" path ":" Path ", #" Browse ":" Select ", # "Set succeeded!": "Setup succeeded! ", #" left Limit ":" Set the right Boundary "," # ":" Set the Boundary ", #" Preset ":" Preset point ", #" Cancel ":" Cancel ", #" Set PTZ ":" Gimbal setting ", #" Auto -scan ":" Linear Scan ", #" delete ":" Delete "#" Add ":" Add ", #" Set failed! ":" Setup failed! ", #" OK ":" OK ", #}
Linux Shell multifile content Replace with SED