CSV file exchanging values

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, MudGuard

Post Reply
MT
Posts: 5
Joined: Tue Nov 06, 2007 4:27 pm

CSV file exchanging values

Post by MT »

Hi,
Below is an example of a csv file that I am trying to make some changes to .

0,"H",1,"S","JONNY","23/11/2007",188.91,0,3000620,"","",""
"D","","","",0,1,0,**156.12,0,*156.12,0,1.00,"002","1001","","
0,"H",1,"S","JONNY","23/11/2007",1192.41,0,3000621,"","","
"D","","","",0,1,0,**98.55,0,*985.46,0,10.00,"002","1001","","
0,"H",1,"S","CASH01","23/11/2007",1605.02,0,3000643,"","","
"D","","","",0,1,0,**82.90,0,*1326.46,0,16.00,"002","1001","",

The header line doesn't need changing (it has the "H" at the beginning).The detail line however needs 2 changes ( "D" @ start of line ) .The numbers in bold italics are to be changed to 1.00 .
The number with the * before it (I placed the * there for reference purposes only ) is to be copied and replace the number with ** before it .please note the (*) (**) are not usually present on the csv file .

regards

MT
Last edited by MT on Thu Nov 29, 2007 8:31 am, edited 1 time in total.
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

When you referred to integers did you in fact mean numbers? If so:
Find what: ^("D",([^,]*,){6})[^,]*,([^,]*,)([^,]*,)([^,]*,)[^,]*,
Replace with: \1\4\3\4\51.00,

[X] Regular expression

Replace All
This assumes you are using Posix regular expression syntax:
Configure | Preferences | Editor

[X] Use POSIX regular expression syntax
MT
Posts: 5
Joined: Tue Nov 06, 2007 4:27 pm

Post by MT »

That works well .Thanks for that .
Is it possible you could explain what was you've done there to get this working .I'm finding it hard to get a list of the conditions for regex.Could you point me in the right direction.
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

^("D",([^,]*,){6})[^,]*,([^,]*,)([^,]*,)([^,]*,)[^,]*, matches

Code: Select all

^             the beginning of a line

(             start of captured text number 1
  "D",          the literal text: "D",
  (             start of captured text number 2 (but we don't use it)
    [^,]*,        any text not containing commas, followed by a comma
                    (see below)
  )             end of captured text number 2
  {6}           ... 6 times
)             end of captured text number 1

[^,]*,        any text not containing commas, followed by a comma

(             start of captured text number 3
  [^,]*,        any text not containing commas, followed by a comma
)             end of captured text number 3

(             start of captured text number 4
  [^,]*,        any text not containing commas, followed by a comma
)             end of captured text number 4

(             start of captured text number 5
  [^,]*,        any text not containing commas, followed by a comma
)             end of captured text number 5

[^,]*,        any text not containing commas, followed by a comma
[^,]*, matches:

Code: Select all

[^,]          any character except newline or comma 
*             ... any number (possibly zero) of times
,             a comma
We glue this back together in a slightly different order and adjusted as required:

\1\4\3\4\51.00, is composed of:

Code: Select all

\1      captured text number 1
\4      captured text number 4
\3      captured text number 3
\4      captured text number 4
\5      captured text number 5
1.00    the literal text: 1.00
,       a comma
Look in TextPad's help under
Reference Information | Regular Expressions,
Reference Information | Replacement Expressions and
How to... | Find and Replace Text | Use Regular Expressions.

There are many regular expression tutorials on the web, and you will find recommendations for some of them if you search this forum.

A standard reference for regular expressions is

Friedl, Jeffrey E F
Mastering Regular Expressions, 3rd ed
O'Reilly, 2006
ISBN: 0-596-52812-4
http://regex.info/

But be aware that the regular expression recogniser used by TextPad is rather weak by the standards of recent tools, so you may get frustrated if you discover a handy trick that doesn't work in TextPad.
MT
Posts: 5
Joined: Tue Nov 06, 2007 4:27 pm

Post by MT »

thanks for that ,much appreciated
Post Reply