wripeでバックアップしたtxtファイルの中身からファイル名を変更する

bash script でwripeバックアップファイルの変換処理を書いた 主な内容 bash script Ubuntu 14.04で確認 UTF8,LF変換にnkf のインストールが必要 ファイル変換内容 1行目(wripeタイトル)から、ファイル名決定 ファイル名に使用できる文字列変換 wripeタイトルに日付が入っていた場合の処理をある程度考慮 1行目は削除 UTF8,LF変換 tag 空白4文字変換 起動引数 第一引数:バックアップファイルの保存先 疲れた…. #!/bin/bash DIR_IN=$1 OUT_NAME=out DIR_OUT=$DIR_IN/$OUT_NAME which nkf 1>/dev/null 2>/dev/null RC=$? if [ $RC -ne 0 ]; then echo "nkf not installed!" return fi if [ "" == "$1" ]; then echo "arg1(input directory) is blank!" return fi if [ -d $DIR_IN ]; then # specified directory is exist. if [ -e $DIR_OUT ]; then # out dir is exist. echo "out dir $DIR_OUT exist! ok!" if [ -f $DIR_OUT ]; then # file echo "out dir $DIR_OUT is file..." return fi else # out dir is not exist. echo "make $DIR_OUT directory!" mkdir -p $DIR_OUT fi else echo "$DIR_IN is not exist or file!" return fi err_files="" for f in `find $1 -type d -name "$OUT_NAME" -prune -o -type f -name "*.txt" -o -name "*.md" -print` do # ファイルの1行目をline変数へ格納 line=`head -n 1 "$f"` # echo ${line} # => 「YYYY/M/D タイトル」形式 # 最初に出てくるドット、またはスペースを区切りに後ろを削除 dt=`echo ${line} |sed -E "s/[\.| ].+//g"` if [[ "$dt" =~ ^[0-9]{8}$ ]]; then # "YYYYMMDD ","YYYYMMDD." に一致 # ~は正規表現を使用するの意味 # echo "matched" ymd="$dt" elif [[ "$dt" =~ ^[0-9]{4}\/[0-9]{1,2}\/[0-9]{1,2}$ ]]; then # "YYYY/M/D ","YYYY/M/D." に一致 # echo "matched date" # 日付取り出し&ゼロパディング yyyy=`echo ${dt} |sed -E "s|^([0-9]+)/([0-9]+)/([0-9]+)|\1|g"` mm=`echo ${dt} |sed -E "s|^([0-9]+)/([0-9]+)/([0-9]+)|\2|g"` if [[ ! "$mm" =~ ^0[0-9]$ ]]; then mm=`printf "%02d" $mm` fi dd=`echo ${dt} |sed -E "s|^([0-9]+)/([0-9]+)/([0-9]+)|\3|g"` if [[ ! "$dd" =~ ^0[0-9]$ ]]; then dd=`printf "%02d" $dd` fi ymd="$yyyy$mm$dd" else echo "[Error] Unknown date format! file=$f dt=$dt" err_files="${err_files}${f}\n" continue fi # ファイルの1行目からタイトルのみ取り出し # name=`echo ${line} |sed -E "s|^[0-9]+/[0-9]+/[0-9]+ +||g"` name=`echo ${line} |sed -E "s|^$dt[\.| ]+||g"` echo "$f => ${name}" # 特殊文字列置換 # echo $name # name=`echo $name |sed -E "s| |_|g"` name=`echo $name |sed -E "s|\(|(|g"` name=`echo $name |sed -E "s|\)|)|g"` # ファイルコピー&変換 newfilename="$ymd.$name.md" # echo $newfilename newfilepath=$DIR_OUT/$newfilename if [ -e "$newfilepath" ]; then # 同一ファイルが存在した場合 echo "[Error] File Already Exist! file=$f" err_files="${err_files}${f}\n" continue fi echo "copy and convert file! $f => \"$newfilepath\"" # file copy. cp "$f" "$newfilepath" # LF UTF8 convert. # echo "convert file LF!UTF8! $newfilepath" nkf -wLu --overwrite "$newfilepath" # head one line delete!. # echo "head one line delete! $newfilepath" sed -e '1,1d' "$newfilepath" > "$newfilepath.tmp.md" # tab space convert. # echo "convert file tab to space! $newfilepath" sed -e "s/\t/ /g" "$newfilepath.tmp.md" > "$newfilepath" # tmp file delete rm "$newfilepath.tmp.md" done if [ ! "$err_files" == "" ]; then echo "-------------------------------" echo "Error file is Exist!" echo "" printf "$err_files" echo "" echo "-------------------------------" else echo "" echo "success!" echo "" fi

2014-10-19 ·  2014-10-19 · 2 分 · 421 文字

Google Bloggerで highlight.js をつかう

Edit HTML and add this under title tag in head tag. <!-- jokrlzy add --> <!-- <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" type="text/javascript" ></script> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.3/styles/monokai_sublime.min.css"> --> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.3/styles/github.min.css"/> <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.3/highlight.min.js"></script> <script>hljs.initHighlightingOnLoad();</script> <!-- jokrlzy add --> add custom css body, textarea { font-size: 20px; font-family: "meiryo","メイリオ","ヒラギノ角ゴ Pro W3", "MS Pゴシック", sans-serif; } h1 {font-size: 60px;} h2 {font-size: 50px;} h3 {font-size: 40px;} h4 {font-size: 30px;} h5 {font-size: 20px;} pre {margin-left: 30px;}

2014-10-18 ·  2014-10-18 · 1 分 · 68 文字

Ubuntu 14.04 Change LF UTF-8 Under Specified Directory

Install nkf sudo aptitude install nkf usege nkf -wLu --overwrite *.txt # -w: change to UTF8 # -Lu: change to LF # --overwrite: overwrite file! Exclude .git or and so on files, and specified some extension. find . \( -name "i18n" -o -name ".git" -o -name "jquery*.js" -o -name "jquery*.css" \) -prune -o -type f \( -name "*.txt" -o -name "*.js" -o -name "*.css" -o -name "*.html" -o -name "*.php" \) -print -exec nkf -wLu --overwrite {} \;

2014-10-12 ·  2014-10-12 · 1 分 · 78 文字

debian wheezy mysql 設定、データ移行

インストール sudo aptitude install mysql-server alive check mysqladmin ping -u root -p mysqlパスワード変更 mysql -u root -p rootパスワード入力 SET PASSWORD FOR root@localhost=PASSWORD('new_password'); ユーザ確認 ログイン mysql -u root -p SQL実行 SELECT host,user,password FROM mysql.user; 文字コード設定 charset UTF8 check mysql> status -------------- mysql Ver 14.14 Distrib 5.5.38, for debian-linux-gnu (armv7l) using readline 6.2 Connection id: 39 Current database: Current user: root@localhost SSL: Not in use Current pager: stdout Using outfile: '' Using delimiter: ; Server version: 5.5.38-0+wheezy1 (Debian) Protocol version: 10 Connection: Localhost via UNIX socket Server characterset: utf8 Db characterset: utf8 Client characterset: utf8 Conn. characterset: utf8 UNIX socket: /var/run/mysqld/mysqld.sock Uptime: 5 hours 20 min 7 sec Threads: 1 Questions: 114 Slow queries: 0 Opens: 171 Flush tables: 1 Open tables: 41 Queries per second avg: 0.005 if your env is not seted to utf8, add utf8 settings below sudo vim /etc/mysql/conf.d/character_set.cnf ...

2014-10-11 ·  2014-10-11 · 3 分 · 426 文字

Linkstation(debian wheezy) へ mysql を設定、データ移行

インストール sudo aptitude install mysql-server alive check mysqladmin ping -u root -p mysqlパスワード変更 mysql -u root -p rootパスワード入力 SET PASSWORD FOR root@localhost=PASSWORD('new_password'); ユーザ確認 ログイン mysql -u root -p SQL実行 SELECT host,user,password FROM mysql.user; 文字コード設定 charset UTF8 check mysql> status -------------- mysql Ver 14.14 Distrib 5.5.38, for debian-linux-gnu (armv7l) using readline 6.2 Connection id: 39 Current database: Current user: root@localhost SSL: Not in use Current pager: stdout Using outfile: '' Using delimiter: ; Server version: 5.5.38-0+wheezy1 (Debian) Protocol version: 10 Connection: Localhost via UNIX socket Server characterset: utf8 Db characterset: utf8 Client characterset: utf8 Conn. characterset: utf8 UNIX socket: /var/run/mysqld/mysqld.sock Uptime: 5 hours 20 min 7 sec Threads: 1 Questions: 114 Slow queries: 0 Opens: 171 Flush tables: 1 Open tables: 41 Queries per second avg: 0.005 if your env is not seted to utf8, add utf8 settings below sudo vim /etc/mysql/conf.d/character_set.cnf ...

2014-10-11 ·  2014-10-11 · 3 分 · 427 文字