ファイルセパレータ(/)を\/に置き換える必要が出てきてsedでやったらなんかヤバくなったお話。
例えば
/Users/miro/Documents/develop/node
というパスを
\/Users\/miro\/Documents\/develop\/node
という感じにしたいという要望。
もうこの時点で見る気がしないが、あくまで機械が読むので辛抱してください。
最初にやったのがこんな感じ。
pwd | sed -e "s/\//\\\\\//g"死にそう。
調べたらこんな感じの書き方もあるみたい。
pwd | sed -e "s%/%\\\/%g"若干マシ・・・?
正規表現でやると\も/もエスケープする必要がある文字なのでカオスな事になりました。
なんかもっといい方法あると思うので、知ってたら誰か教えてください。
ちなみにScalaだとこんな感じ。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"/a/b/c".replaceAll("""/""", """\\/""") | |
// \/a\/b\/c |
0 件のコメント:
コメントを投稿