sedを使用してファイル内の(*)で始まるリストを置き換える方法

sedを使用してファイル内の(*)で始まるリストを置き換える方法

sedアスタリスクで始まる行をどのように変更し、1から始まる数字に置き換えますか?

リストの先頭の(*)を数字に置き換えるには、sedを使用する必要があります。>

ファイルにリストが含まれています。

*linux

*computers

*labs

*questions

>>>>に行く

ファイルにリストが含まれています。

1 linux
2 computers
3 labs
4 questions

使ってみよう

sed -e 's/*//' file.in > file.out | sed -i = file.out

ベストアンサー1

awkを使用できます。

awk '/^\*/ {sub(/\*/, ++i)} 1' <<END
A list
* one
* two
Blah
* three
END
A list
1 one
2 two
Blah
3 three

おすすめ記事