2
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?

More than 3 years have passed since last update.

[Windows]sedでスペースをタブにする

Last updated at Posted at 2020-03-05

前書き

 経緯は忘れましたが、ツールで生成したスペースインデントなコードを、タブインデントなソースに貼りたかったんだと思います(曖昧)。
その前処理の際、タブへの変換が意外と手こずったので、備忘として残しておこうと思ったのでした。

本題

ファイルの各行に登場する、最初のスペースだけをタブに置換する

> cat target.txt | sed -r "s/ /\t/" > result.txt

sed -eだと置換されなかった、謎!
しかも<tab>とか<space>も上手くいかない、謎!!

参考

sedでスペースをタブに置換 (連続スペースは1文字とみなす)

2
0
0

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
2
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?