ときどきの雑記帖 RE* (新南口)
二月のかもめ
今週も月-金の間に一つは書けると思ってたんだけど挫けた。
Pico
出遅れた orz
pragmatic programmer
なんかmediumからメールが来ていて(アカウントを作ってはいた)。
Today, we’re excited to share that The Pragmatic Programmers are now on Medium. For over 20 years, The Pragmatic Programmers have helped a generation of programmers dive into the world of software development, independent of any language, framework, or methodology. By upgrading to a Medium membership, you’ll get unlimited access to their full catalog — as well as future additions — as part of Medium’s ever-growing premium content.
(略)
Because of our members, we can keep adding quality publications, writers, and content for you and other readers to explore and learn from. If you’d like to get unlimited access and support writers on Medium, consider becoming a member today.
ん-、どうしようかなあ。
これは Hacker News Pragmatic Programmers Entire Catalog on Medium | Hacker News でも話題になっていた。 が、あまり伸びてないすな。
以前どこかで書いたのだけど、Mediumは有料のページなのかそうでないのかを リンクから判断することができないのであまり好きではなくて、 Hacker News や reddit でMediumのページが取り上げられていてそれが興味をひかれる ものであっても避けることが多い。
たまーに間違ってアクセスしてしまい、それが星付き(有料ページ)だったりすると 「むきー」となる(笑)。 あらかじめ有料ページと分かった上でそれを承知(納得)してアクセスすることもあるんだけどね (月に何ページかは無料で見られるので)。
サブスクリプションするかどうかはずっと悩んでいる 😄
Pragmatic Programmer Books on Medium のDirectory ページはこちら Directory of Pragmatic Programmer Books on Medium | by The Pragmatic Programmers | The Pragmatic Programmers | Jan, 2021 | Medium
お、Hugoの本もある(持ってるけど)。
プログラマーの脳みそ
manning の MEAPにこんな本 Manning | The Programmer’s Brain があるのを発見。
このタイトル、日本語版が出るとしたらどんなタイトルになるんでしょうか (「プログラマーの脳みそ」では某氏のblogタイトルに 😄 )
About the book
The Programmer’s Brain explores the way your brain works when it’s thinking about code. In it, you’ll master practical ways to apply these cognitive principles to your daily programming life. You’ll improve your code comprehension by turning confusion into a learning tool, and pick up awesome techniques for reading code and quickly memorizing syntax. This practical guide includes tips for creating your own flashcards and study resources that can be applied to any new language you want to master. By the time you’re done, you’ll not only be better at teaching yourself—you’ll be an expert at bringing new colleagues and junior programmers up to speed.
MEAP の値引きがあったら買ってみようかな。
数日前からリンク先を直接開けなくなって
(一度pocket内でリンク先の内容を見る形になっていて、オリジナルを見るには
view original
をクリックしないといけない)
すげー不便。
sed
sedで改行を追加できなかったのでcatとechoで対応した話 - Qiita
sed -i '' -e '1s/^/追加文字列\n/' (ファイルパス)
上記では文字列は追加できるが、改行だけ改行として認識されず、nが出力されてしまう。
sedコマンドで改行を挿入する方法として、gnu-sedを入れるなどの方法があったが、うまく使いこなせなかったのでもう少し調査をしようと思います。
sed の s コマンドの replacement 部では\nや\tのようなエスケープシーケンスが 有効にならない(ケースがよくある)というのは失われつつある情報なんですかねえ。 GNU拡張が「あってあたりまえ」のような。
opengroup のドキュメント sed でどうなっているか確かめてみると
The meaning of a ‘' immediately followed by any character other than ‘&’, ‘', a digit, or the delimiter character used for this command, is unspecified.
sed ではこう。
It is unspecified what special meaning is given to any character other than &, \ or digits.
「未定義」ということか。
sed のGNU拡張と言えば
3.3 The s Command
(略)
Finally, as a GNU sed extension, you can include a special sequence made of a backslash and one of the letters L, l, U, u, or E. The meaning is as follows:
これもGNU拡張だったのかー。
ってまあさっきのopengroup のドキュメントにも使えるとは書かれてなかったし。 元(?)はviだかexから来たものだったと思うけど(Perlにもある perlrebackslash - Perl 正規表現逆スラッシュシーケンスとエスケープ - perldoc.jp)。
あったあった。 ex
Replacement Strings in ex
(略)
The strings ‘\l’, ‘\u’, ‘\L’, and ‘\U’ can be used to modify the case of elements in the replacement string (using the ‘&’ or “" digit) notation. The string ‘\l’ ( ‘\u’ ) shall cause the character that follows to be converted to lowercase (uppercase). The string ‘\L’ ( ‘\U’ ) shall cause all characters subsequent to it to be converted to lowercase (uppercase) as they are inserted by the substitution until the string ‘\e’ or ‘\E’, or the end of the replacement string, is encountered.
An example of case conversion with the s command is as follows:
:p
The cat sat on the mat.
:s/\<.at\>/\u&/gp
The Cat Sat on the Mat.
:s/S\(.*\)M/S\U\1\eM/p
The Cat SAT ON THE Mat.
- sedを使って特定の文字列から文字列までを抜き出す
- sedコマンドで文字列を改行に置換する、しかもスマートに置換する。 - Qiita
- sed による置換で改行\nを出力する - Qiita
- Mac(BSD)でcpをGNU的に使う + おまけ
そこまで苦労(?)してsedを使うこたないような気もするんだが。
BRE
sed でもうひとつ。
ポイントとして、正規表現の|がsedの特殊文字扱いになるのでバックスラッシュでエスケープする必要があります。
|^$| → \|^$\|
sed では |
は特殊文字でもなんでもなくて、
\|
と書いたときに正規表現演算子(メタ文字)になるのはGNU拡張なんだけどなあ。
regexp1\|regexp2
Matches either regexp1 or regexp2. Use parentheses to use complex alternative regular expressions. The matching process tries each alternative in turn, from left to right, and the first one that succeeds is used. It is a GNU extension.
このほかにも \+
や \?
が GNU sed で\
をつけると正規表現演算子になるもの。