Split input into multiple content-based exits?

Suppose there is a file that looks like this:

xxxx aa whatever
yyyy bb whatever
zzzz aa whatever

I would like to split it into 2 files containing:

the first:

xxxx aa whatever
zzzz aa whatever

second:

yyyy bb whatever

those. I want to group the lines based on some value in the lines (the rule may be: the 2nd word is separated by spaces), but not reorder the lines inside the groups.

Of course, I can write a program for this, but I wonder if there is any ready-made tool that can do something like this?

Sorry, I didn’t mention this, since I assumed that it was pretty obvious - the number of different “words” is huge. we are talking about no less than 10,000 of them. That is, any solution based on the listing of words before hand will not work.

- - , , .

+3
2

output.aa, output.bb ..:

awk '{print >> "output." $2}' input.file
+6

, grep, , grep -v - , .

Hm, sort -f" " -s -k 2,2, O (n log n).

+1

Source: https://habr.com/ru/post/1775688/


All Articles