Need help with regex | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Need help with regex

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 08-28-2013
before4 before4 is offline
Registered User
 
Join Date: Feb 2012
Last Activity: 28 August 2013, 11:24 AM EDT
Posts: 23
Thanks: 9
Thanked 0 Times in 0 Posts
Linux Need help with regex

i have some giga texts data, samples data below


Code:
803,7282012,343
703,7282013,0
600,7282012,0
600,7282012,0
600,7282012,0
600,7282012,0
803,7282012,277
600,7282012,0
403,7282012,0
303,7282013,7613
600,7282013,0
501,7282013,0
403,7282013,4079
803,7282013,0
600,7282013,0
303,7282013,0
803,7282013,7015
703,7282013,0
501,7282013,32568
600,7282013,0
703,7282013,10362

i want to extract the data for each date (column no.2) and stored to separate files, any line contain 7282012 will stored to 7282012.txt

sorry for my bad English
Sponsored Links
    #2  
Old 08-28-2013
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
Moderator
 
Join Date: Jan 2007
Last Activity: 24 July 2014, 9:57 AM EDT
Location: Варна, България / Milano, Italia
Posts: 5,663
Thanks: 182
Thanked 616 Times in 574 Posts
You may try something like this:

Code:
awk -F, '{ print > ($2 ".txt") }' infile

Note that some awk implementations (or some system settings) could limit the number of concurrently open files.

Last edited by radoulov; 08-28-2013 at 12:04 PM..
The Following User Says Thank You to radoulov For This Useful Post:
before4 (08-28-2013)
Sponsored Links
    #3  
Old 08-28-2013
before4 before4 is offline
Registered User
 
Join Date: Feb 2012
Last Activity: 28 August 2013, 11:24 AM EDT
Posts: 23
Thanks: 9
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by radoulov View Post
You may try something like this:

Code:
awk -F, '{ print > ($2 ".txt") }' infile

Note that some awk implementations (or some system settings) could limit the number of concurrently open files, in that case you could use something like this:


Code:
awk -F, '{
  fn[f = $1 ".txt"]++ || c++ 
  if (c >= l) {
    for (F in fn) close(F)
    c = x
    }
  print >> f
  }' l=10 infile

Set l to the desired value (the # of open files).
thanks it's working well and also very fast. never think it's can be done by single line awk. i want to know also how to calculate the number of record base on value on column 1 and 2 , so the data after i extract is


Code:
8,7282012,343
7,7282013,0
6,7282012,0
6,7282012,0
6,7282012,0
6,7282012,0
8,7282012,277

the output that i want is

Code:
8,7282012,2
7,7282013,1
6,7282012,4

thanks in adv
    #4  
Old 08-28-2013
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
Moderator
 
Join Date: Jan 2007
Last Activity: 24 July 2014, 9:57 AM EDT
Location: Варна, България / Milano, Italia
Posts: 5,663
Thanks: 182
Thanked 616 Times in 574 Posts

Code:
awk -F, 'END {
  for (e in cnt)
    print e, cnt[e]
  }
{ cnt[$1 FS $2]++ }
 ' OFS=, infile

The Following User Says Thank You to radoulov For This Useful Post:
before4 (08-28-2013)
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
read regex from ID file, print regex and line below from source file pathunkathunk UNIX for Dummies Questions & Answers 3 10-08-2012 08:52 PM
Converting perl regex to sed regex suntzu Shell Programming and Scripting 1 10-30-2010 06:16 AM
Regex saikrishnan7 Shell Programming and Scripting 1 05-30-2009 08:38 PM
Regex deepakpv Shell Programming and Scripting 6 03-28-2007 04:18 AM
Regex?? Please help lunac UNIX for Dummies Questions & Answers 7 01-30-2007 12:13 PM



All times are GMT -4. The time now is 09:34 PM.