Linux Shell multifile content Replace with SED

Source: Internet
Author: User

#!/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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.