user1411254
user1411254

Reputation: 139

Notepad++ - Remove second and third comma in a csv in one shot

i have a csv file having thousands of lines of data with comma delimited, i need to remove 2nd and 3rd commas from those lines

example below

8213201711,77,429,890,5d810ffc6
9801201711,103,088,818,5d810ffc
8113201711,102,829,857,5d810ffb
8113201711,104,186,726,5d810ffc
8101201711,86,337,068,5d810ffb1
8205201711,77,137,917,5d72788c9

I need

8213201711,77429890,5d810ffc6
9801201711,103088818,5d810ffc
8113201711,102829857,5d810ffb
8113201711,104186726,5d810ffc
8101201711,86337068,5d810ffb1
8205201711,77137917,5d72788c9

I tried to find

^([^,]*,[^,]*),(.*)$

and replace with

\1\2

but, its removing only 2 occurrence

Upvotes: 0

Views: 1439

Answers (2)

Toto
Toto

Reputation: 91385

  • Ctrl+H
  • Find what: ^\d+,\d+\K,(\d+),
  • Replace with: $1
  • check Wrap around
  • check Regular expression
  • Replace all

Explanation:

^           : begining of line
  \d+       : 1 or more digits
  ,         : a comma
  \d+       : 1 or more digits
  \K        : forget all we have seen until this position
  ,         : a comma
  (\d+)     : group 1, 1 or more digits
  ,         : a comma

You may use [^,] instead of \d if you have other character than digits.

Replacement:

$1          : content of group 1 (ie. the digits between 2nd and 3rd comma)

Result for given example:

8213201711,77429890,5d810ffc6
9801201711,103088818,5d810ffc
8113201711,102829857,5d810ffb
8113201711,104186726,5d810ffc
8101201711,86337068,5d810ffb1
8205201711,77137917,5d72788c9

Upvotes: 0

shawnt00
shawnt00

Reputation: 17915

Try

^([^,]*,[^,]*),([^,]*),(.*)$

and

\1\2\3

Note that the 2nd and 3rd literal commas in the expression are outside parens.

EDIT: I guess it would have been simpler from a minimal edit standpoint to use ^([^,]*,[^,]*),([^,]*),(.*), and \1\2. I wasn't sure off the top of my head all of the search and replace options that I might have been overlooking so it seemed safer to work with the whole line. In hindsight that was probably silly.

Upvotes: 1

Related Questions