1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

記事投稿キャンペーン 「2024年!初アウトプットをしよう」

改行を含むテキストを改行コードを含む一行に変換する

Last updated at Posted at 2024-01-16

毎回調べてるので自分へのメモ用に。
改行コード\nの場合(Mac)

bash

$ cat hoge.txt
111
222
333
$ cat hoge.txt | tr \\n \\ | sed -e 's/\\/\\n/g'
111\n222\n333\n

fish

エスケープの仕方がちょっと違う

$ cat hoge.txt | tr \\n \\ | sed -e 's/\\\/\\\n/g'
111\n222\n333\n
1
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?