Pedro Rosa
Pedro Rosa

Reputation: 19

Split columns based on a specific column

I have a number of files with 2 or more columns, and I need to split the columns that are not the first based on the first column. Ex:

1 15 90
4 20 89
1 38 129
4 56 150
4 43 171
1 45 210

So, I need, in file1:

1 15 90
1 38 129
1 45 210

And in file 2:

4 20 89
4 56 150
4 43 170

Can anyone help? Thanks a lot, Pedro.

Upvotes: 1

Views: 78

Answers (1)

Ed Morton
Ed Morton

Reputation: 203169

awk '{print > ("file" $1)}' file

Upvotes: 2

Related Questions