Extracting variables between commas : GAWK or SED

Hello,

I need some help,

I got a CSV file called test.txt with this text in it :

08/02/2011;0,677;0,903;1,079;1,336;1,513;1,683 

There's only a line and i need to copy theese numbers into variables :

0,677
0,903
1,079
1,336
1,513
1,683

The output file should look like this :

IN      TAUX1                                    20110208D  0,677          0,677
IN      TAUX2                                    20110208D  0,903          0,903
ETC ...

I'm under windows7 and but i have SED and GAWK installed.

Can someone Help me doing this ? With Gawk I always get a parse error while setting the FS to ";"

Thanks a lot for your Help guys !

Julien

Try:

awk 'NR==1{split($0,a,"/");next}
{print "IN\tTAUX" ++c "\t" a[3] a[2] a[1] "D\t"  $1 "\t" $1}
' RS=";" file
1 Like

I wrote this Batch File :

gawk 'NR==1{split($0,a,"/");next}
{print "IN\tTAUX" ++c "\t" a[3] a[2] a[1] "D\t"  $1 "\t" $1}
' RS=";" C:\file.txt
pause

Dos returns me this Error message :

C:\Documents and Settings\julien.lacombe\Desktop>gawk 'NR==1{split($0,a,"/");nex
t}
gawk: cmd. line:1: 'NR==1{split($0,a,/);next}
gawk: cmd. line:1: ^ invalid char ''' in expression

C:\Documents and Settings\julien.lacombe\Desktop>{print "IN\tTAUX" ++c "\t" a[3]
 a[2] a[1] "D\t"  $1 "\t" $1}
'{print' is not recognized as an internal or external command,
operable program or batch file.

C:\Documents and Settings\julien.lacombe\Desktop>' RS=";" C:\file.txt
''' is not recognized as an internal or external command,
operable program or batch file.

C:\Documents and Settings\julien.lacombe\Desktop>pause
Press any key to continue . . .

Thanks for your time, I'm currently learning Batch et Gawk scripting !

---------- Post updated at 05:48 AM ---------- Previous update was at 05:43 AM ----------

I changed my Batch file into :

gawk "NR==1{split($0,a,"/");next}{print "IN\tTAUX" ++c "\t" a[3] a[2] a[1] "D\t"  $1 "\t" $1}" RS=";" C:\file.txt 
pause

And dos returns me this Error :

C:\Documents and Settings\julien.lacombe\Desktop>gawk "NR==1{split($0,a,"/");nex
t}{print "IN\tTAUX" ++c "\t" a[3] a[2] a[1] "D\t"  $1 "\t" $1}" RS=";" C:\file.t
xt
gawk: cmd. line:1: NR==1{split($0,a,/);next}{print IN\tTAUX ++c \t a[3] a[2] a[1
] D\t  $1 \t $1}
gawk: cmd. line:1:                   ^ unterminated regexp
gawk: cmd. line:2: NR==1{split($0,a,/);next}{print IN\tTAUX ++c \t a[3] a[2] a[1
] D\t  $1 \t $1}
gawk: cmd. line:2:
                ^ unexpected newline

C:\Documents and Settings\julien.lacombe\Desktop>pause
Press any key to continue . . .

Probably you should escape the double quotes, try this in one line:

gawk "NR==1{split($0,a,\"/\");next}{print \"IN\tTAUX\" ++c \"\t\" a[3] a[2] a[1] \"D\t\"  $1 \"\t\" $1} " RS=";" file

Wooow ! Thanks a lot !!

Actually, I have a last question : I wrote TAUX1, TAUX2,TAUX3 ... But in fact TAUX1 = EONIA ... TAUX2=EURIBOR ... TAUX3 = EUR3M ...

IS THERE A SIMPLE WAY TO CHANGE THEM ?

---------- Post updated at 06:18 AM ---------- Previous update was at 06:06 AM ----------

And hum, is there a way to store each number in a separated variable ?
Like :
$1 = 0,677
$2 = 0,903
$3 = 1,079

Thanks for your time !

How to determine when to use EONIA, EURIBOR, EURM3?
And how about TAUX4, TAUX5 ,TAUX6.......

I don't know how to do that in windows....