Mar 16, 2023

awkの1行野郎

青空文庫で公開している「週刊詩」を、すべてAIで英語に翻訳して1冊の本にしようという計画が頭に浮かんだ。
うっかりテキストファイルがどこかに行ってしまったので、サイトにあるHTMLファイルを、chatGPTを使って加工して1つのファイルにすることにした。
1. まず文字コードがshift-sだったので、utf-8に変換する。
2. すべてのhtmlタグを取り除く。
3. 200以上あるテキストファイルを一つにまとめる。

まず3.から。
これはコマンドライン1行でうまくいく。
コマンドラインラインです。
cat $(find . -maxdepth 1 -type f -name "*.txt" | sort) | awk 'BEGIN{RS="";ORS="\n\n\n\n"}{print}' > all.txt
下の文章はchatGPTで英語に翻訳しています。

Awk One-Liner

The idea came to mind to translate all the "Weekly Poems" available on Aozora Bunko into English using AI and compile them into a single book. Since the text file had accidentally gone missing, I decided to use chatGPT to combine them into one file.

First, since the character code was shift-s, I converted it to utf-8. Then, I removed all the HTML tags. Finally, I consolidated over 200 text files into one.

Let's start with step 3. This can be done with a single command line. I'll add it here tomorrow as it's difficult to write it down now.

23_03_16a

Posted at 20:58 in n/a | WriteBacks (0) | Edit
WriteBacks
TrackBack ping me at
http://www.haizara.net/~shimirin/blosxom/blosxom.cgi/20230316205014.trackback
Post a comment

writeback message: Ready to post a comment.













Captcha:
To prevent comment spam, please retype the characters in this image:

Enter the text here: