grep信息并另存为Excel可读的文件?

grep信息并另存为Excel可读的文件?,excel,csv,awk,grep,Excel,Csv,Awk,Grep,我有以下文件 There is a group of Lion in the forest. There are 3 active. There are 1 sleeping Lion1 is talking to Lion2 Lion2 is talking to Lion3 Lion3 is touching Lion1 There is a group of Turtle in the forest. There are 1 active. There are 0 slee

我有以下文件

There is a group of Lion in the forest. There are 3 active. There are 1 sleeping

  Lion1 is talking to Lion2
  Lion2 is talking to Lion3
  Lion3 is touching Lion1

There is a group of Turtle in the forest. There are 1 active. There are 0 sleeping

There is a group of Monkey in the forest. There are 4 active. There are 0 sleeping

  Monkey1 is talking to Monkey3
  Monkey4 is jumping about

There is a group of Panda in the forest. There are 2 active. There are 1 sleeping

There is a group of Owl in the forest. There are 5 active. There are 4 sleeping
我使用了以下命令:

grep "There is a group" | awk '{print substr($0,10)}'
我得到如下结果

Lion in the forest. There are 3 active. There are 1 sleeping
Turtle in the forest. There are 1 active. There are 0 sleeping
Monkey in the forest. There are 4 active. There are 0 sleeping
Panda in the forest. There are 2 active. There are 1 sleeping
Owl in the forest. There are 5 active. There are 4 sleeping
问题

如何修改grep和awk命令以获得以下结果:

Lion, 3, 1
Turtle, 1, 0
Monkey, 4, 0
Panda, 2, 1
Owl, 5, 4
结果将存储到Microsoft Excel读取的文件中。在Microsoft Excel中,我可以看到以下三列:

=========================== | Lion | 3 | 1 | | Turtle | 1 | 0 | | Monkey | 4 | 0 | | Panda | 2 | 1 | | Owl | 5 | 4 | =========================== =========================== |狮子| 3 | 1| |乌龟| 1 | 0| |猴子| 4 | 0| |熊猫| 2 | 1| |猫头鹰| 5 | 4| ===========================
感谢您提供的任何帮助。

根据数据的规律性,您可以通过替换以下内容直接寻址字段:

grep "There is a group" | awk '{print substr($0,10)}'

输出:

Lion, 3, 1
Turtle, 1, 0
Monkey, 4, 0
Panda, 2, 1
Owl, 5, 4

谢谢你的回答。我已经编辑了你的答案,让它更清晰,杰克,你把
grep
放回那里,但是当你已经在
awk
@wich中进行模式匹配时,你就不再需要它了。谢谢你的来信。我对答案做了一些修改。很高兴它起了作用,我更新了答案,使用了输出字段分隔符(
OFS
),而不是显式插入逗号。@Thor。酷!从来没有想过它可以真正使用OFS的
Lion, 3, 1
Turtle, 1, 0
Monkey, 4, 0
Panda, 2, 1
Owl, 5, 4