Skip to content

Instantly share code, notes, and snippets.

@ZoomQuiet ZoomQuiet/zhmark2en.sh Secret
Last active Jul 24, 2018

Embed
What would you like to do?
i hate Chinese symbol! so usage: zhmark2en.sh pwd FILEexNAME
#!/bin/sh
VER="zhmark2en.sh {v12.6.27}"
echo "$#"
if [ "$#" -ne 3 ]; then
echo "usage: zhmark2en.sh pwd FILEexNAME"
exit 0
fi
SED="$(which sed)"
PATH=$2
FEX=$3
echo $PATH $FEX
echo "walk @\t" $PATH
cd $PATH
#$SED -ig "s/。/. /g" `/usr/bin/grep 。 -rl ./`
$SED -ig "s/。/. /g; \
s/,/,/g; \
s/、/,/g; \
s/?/\?/g; \
s/!/\!/g; \
s/;/;/g; \
s/“/\"/g; \
s/”/\"/g; \
s/‘/\'/g; \
s/’/\'/g; \
s/﹃/\"/g; \
s/﹄/\"/g; \
s/﹁/\'/g; \
s/﹂/\'/g; \
s/(/(/g; \
s/)/)/g; \
s/《/<</g; \
s/》/>>/g; \
s/【/\[/g; \
s/】/\]/g; \
s/『/\[/g; \
s/』/\]/g; \
s/……/... /g; \
s/:/:/g; \
s/——/--/g" \
$PATH/*.$FEX
#echo "###::end@ " `date +"%Y/%m/%d %H:%M:%S"`
echo "$VER transformed all Chinese Mark into en. ;-)"
exit 0
@ZoomQuiet

This comment has been minimized.

Copy link
Owner Author

ZoomQuiet commented Mar 6, 2014

问题是俺每次

$ zhmark2en ./ md

这样运行后,都产生一大堆 *.mdg 文件,内容是原始文件

参考:
mac os 中用 sed 命令 替换文本中的指定内容

为毛?!

probelm is running:

$ zhmark2en ./ md

will gen. *.mdg files, content originality files

so i just want replace somethin just in originality files.
not need backup.

感谢 SHLUG 高手的热心解答:

发件人:     Felix Yan felixonmars@gmail.com
发送至:     shlug@googlegroups.com
日期:  2014年3月6日 下午7:26
主题:  Re: [shlug] i hate Chinese symbol!

其实就是不认真问 man 的原因!

 -i extension
         Edit files in-place, saving backups with the specified extension.  If a zero-length extension is given, no backup
         will be saved.  It is not recommended to give a zero-length extension when in-place editing files, as you risk
         corruption or partial content in situations where disk space is exhausted, etc.

关键就是那个 zero-length 在bsd样的 sed 中要表述为

sed -i "" "s/。/. /g;...

俺又一次 #图样图森破 了...

@lilydjwg

This comment has been minimized.

Copy link

lilydjwg commented Mar 6, 2014

其实弯角引号/撇号、HORIZONTAL ELLIPSIS(半个中文省略号)和 EM DASH(半个中文破折号)在英文里也使用的呀…

@ZoomQuiet

This comment has been minimized.

Copy link
Owner Author

ZoomQuiet commented Jul 8, 2017

#!/bin/sh
# Change log
#   v15.10.10 upgrade fro EI Captain
#       as http://blog.csdn.net/wqhjfree/article/details/39032533
#       http://stackoverflow.com/questions/11287564/getting-sed-error-illegal-byte-sequence-in-bash
#   v15.4.10 upgrade fro Yosemite
#   v12.6.27 can usage

export LC_COLLATE='C'
export LC_CTYPE='C'

VER="zhmark2en.sh {v15.10.10}"
SED="$(which sed)"

echo "\t powered from $VER"
echo "Number of arguments: $#"

if [ "$#" -lt 1 ]; then
    echo "usage: zhmark2en FILEexNAME(txt/md/...)"
    exit 0
fi
if [ "$#" -gt 2 ]; then
    echo "usage: zhmark2en FILEexNAME(txt/md/...)"
    exit 0
fi

# -eq 等于
# -ne 不等于
# -le 小于等于
# -ge 大于等于
# -lt 小于
# -gt 大于

#echo "?" $0
#echo "??" $1
#echo "???" $2
#echo "????" $3
PATH=$(pwd) #$2
FEX=$1  #$3

echo $PATH $FEX
echo "walk @\t" $PATH
echo "will clean Chinese Mark in :" 
echo *.$FEX
#cd $PATH

#$SED -ig "s/。/. /g" `/usr/bin/grep 。 -rl ./`
#$SED -i "s/。/. /g; \
#$SED -i.orig "s/。/. /g; \
$SED -i "" "s/。/. /g; \
    s/,/,/g; \
    s/、/,/g; \
    s/?/\?/g; \
    s/!/\!/g; \
    s/;/;/g; \
    s/:/:/g; \
    s/……/... /g; \
    s/…/... /g; \

    s/“/\"/g; \
    s/”/\"/g; \
    s/‘/\'/g; \
    s/’/\'/g; \

    s/(/(/g; \
    s/)/)/g; \
    s/{/{/g; \
    s/}/}/g; \

    s/《/\"/g; \
    s/》/\"/g; \
    s/〈/\'/g; \
    s/〉/\'/g; \

    s/〔/\[/g; \
    s/〕/\]/g; \
    s/[/\[/g; \
    s/]/\]/g; \
    s/【/\[/g; \
    s/】/\]/g; \
    s/〖/\[/g; \
    s/〗/\]/g; \

    s/『/\"/g; \
    s/』/\"/g; \
    s/「/\'/g; \
    s/」/\'/g; \

    s/﹃/\"/g; \
    s/﹄/\"/g; \
    s/﹁/\'/g; \
    s/﹂/\'/g; \
    s/——/---/g" \
    $PATH/*.$FEX

#echo "###::end@ " `date +"%Y/%m/%d %H:%M:%S"` 
echo "\t $VER transformed all Chinese Mark into en. ;-)"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.