gpt4 book ai didi

excel - grep 信息并保存为 Excel 可读的文件?

转载 作者:行者123 更新时间:2023-12-02 10:17:13 26 4
gpt4 key购买 nike

我有以下文件

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  |===========================

感谢任何帮助渲染。

最佳答案

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

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

awk -v OFS=', ' '/There is a group/ { print $6, $12, $16 }'

输出:

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

关于excel - grep 信息并保存为 Excel 可读的文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12349149/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com