Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
たとえば、ファイルに「test test test」のような文字列があります。最初のスペースを「1」に置き換えて「テスト 1 テスト テスト テスト」にしたいと思います。
試してみsed -i "s/^\ /\ 1\ /g" text.txtましたが、すべてのスペースが「 1 」に変更されるので、最初に見つかったときにのみ発生させる方法を知りたいですか?
sed -i "s/^\ /\ 1\ /g" text.txt
'g'次のようなオプション (グローバル置換) を使用しないでください。
'g'
sed 's/ / 1 /'