Skip to main content
added 13 characters in body
Source Link
regex
  • 77
  • 1
  • 4

Say I have a large CSV file with a header and several columns. For the purpose of this question I will consider a small file with just two columns. We can call it use_rep.

user_id,rep
885,500K+
22565,200K+
7453,200K+
86440,100K+
116858,100K+
22222,100K+
38906,100K+
10762,<100K
70524,<100K

I'd like to send each row to a file corresponding to the value on the second column. For example, I'd like there to be a file whose name is 200K+ and whose content is

user_id,rep
22565,200K+
7453,200K+

The contents of use_rep should not be assumed to be ordered in anyway. The pattern to be used would ideally accept regular expressions.

No sed or perl is preferred.

Say I have a large CSV file with a header and several columns. For the purpose of this question I will consider a small file with just two columns. We can call it use_rep.

user_id,rep
885,500K+
22565,200K+
7453,200K+
86440,100K+
116858,100K+
22222,100K+
38906,100K+
10762,<100K

I'd like to send each row to a file corresponding to the value on the second column. For example, I'd like there to be a file whose name is 200K+ and whose content is

user_id,rep
22565,200K+
7453,200K+

The contents of use_rep should not be assumed to be ordered in anyway. The pattern to be used would ideally accept regular expressions.

No sed or perl is preferred.

Say I have a large CSV file with a header and several columns. For the purpose of this question I will consider a small file with just two columns. We can call it use_rep.

user_id,rep
885,500K+
22565,200K+
7453,200K+
86440,100K+
116858,100K+
22222,100K+
38906,100K+
10762,<100K
70524,<100K

I'd like to send each row to a file corresponding to the value on the second column. For example, I'd like there to be a file whose name is 200K+ and whose content is

user_id,rep
22565,200K+
7453,200K+

The contents of use_rep should not be assumed to be ordered in anyway. The pattern to be used would ideally accept regular expressions.

No sed or perl is preferred.

Source Link
regex
  • 77
  • 1
  • 4

Extracting lines to new files

Say I have a large CSV file with a header and several columns. For the purpose of this question I will consider a small file with just two columns. We can call it use_rep.

user_id,rep
885,500K+
22565,200K+
7453,200K+
86440,100K+
116858,100K+
22222,100K+
38906,100K+
10762,<100K

I'd like to send each row to a file corresponding to the value on the second column. For example, I'd like there to be a file whose name is 200K+ and whose content is

user_id,rep
22565,200K+
7453,200K+

The contents of use_rep should not be assumed to be ordered in anyway. The pattern to be used would ideally accept regular expressions.

No sed or perl is preferred.