grep information and save as a file readable to Excel?

I have the following file

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

I used the following command:

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

and I get the following

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

Question

How should I modify my grep and awk command such that I get the following result:

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

The result will be store into a file that will be read by Microsoft Excel. Inside the Microsoft Excel, I will be able to see three column as follows:

===========================
|  Lion       |  3  |  1  |
|  Turtle     |  1  |  0  |
|  Monkey     |  4  |  0  |
|  Panda      |  2  |  1  |
|  Owl        |  5  |  4  |
===========================

Appreciate any help render.

Answers


Depending on the regularity of your data, you could just address the fields directly by replacing:

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

with

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

Output:

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

Need Your Help

Java reflection: how do the Method.getGenericXXXXX methods work?

java generics reflection

I just noticed there's a Method.getGenericReturnType() as well as Method.getReturnType() and similar pairs for exception types and parameter types.

What do R_X86_64_32S and R_X86_64_64 relocation mean?

c compiler-construction linker elf relocation

Got the following error when I tried to compile a C application in 64-bit FreeBSD: