regex - How to use Regular Expression In Find and Replacement -


i've 1 csv file has 50k records. want remove unnecessary records file. can tell me how can achieve regex through find , replacement?

the data looks this:

item code,,qty cmac-389109,,6 ,serial no., ,954zg5, ,ffnaw8, ,gh8731, ,gxj419, ,hc6y9q, ,y65vh8, cmac-394140,,1 ,serial no., ,4cu3z7, 

and want convert data below format:

itemcode,serial number,qty cmac-389109,"954zg5, ffnaw8, gh8731, gxj419, hc6y9q, y65vh8",6 cmbm-394140,"4cu3z7",1 

here's regex captures 2 groups (item code , shelf):

^([^,]*?)(?:,(?:[^,]+)?){5},([^,]+),.*$ 

i don't know syntax dw uses reference groups. it's either $n or \n, in case, can put $1, $2 in "replacement" field of search/replace box. or \1, \2.


if have access linux environment (os-x , cygwin should work too), can use command-line tools cut , grep accomplish quite easily:

 cat <filename> | cut -d ',' -f 1,7 | grep -v "^,$" > <output_file> 

the parameters used on cut are:

-d delimiter (by character fields separated)

-f fields (which fields include in output).

... , grep:

-v invert pattern: include lines in output not matching regex.

given data in question, above command yield result:

item code,shelf cmac-386607,m5-2 cmac-389109, f2-3 

this should quite efficient, cut works on stream, , loads data memory necessary. don't need load whole file before executing task. being large file, might handy.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -