sed

上級
1/10
user@linux:~/workspace$
sed 's/Hello/Hi/' file.txt

解説

各行の最初の "Hello" のみ "Hi" に置換されます。

オプション

-iファイルを直接編集(上書き)
-n自動出力を抑制
-e複数のコマンドを実行
s/パターン/置換/置換(1行あたり最初の1つ)
s/パターン/置換/g置換(行内の全て)
55行目のみ
1,101〜10行目
/pattern/パターンに一致する行
$最終行
s///置換
d削除
p表示
a\テキスト行を追加
i\テキスト行を挿入
1Hello, World!
2This is a sample text file for practicing Linux commands.
3You can use commands like cat, head, tail, and grep on this file.
4
5Line 5: Learning Linux commands through typing practice.
6Line 6: WebContainers make it possible to run commands in the browser.
7Line 7: Practice makes perfect!
8Line 8: Keep typing to improve your speed and accuracy.
9Line 9: Linux is widely used in servers and development environments.
10Line 10: Mastering the command line is a valuable skill.