Solved

2 text converting script..

Posted on 1998-02-10
9
276 Views
Last Modified: 2013-12-26
1. First I need a script that creates a new text file in this format:

jonas@home.se:Dear subscriber
96bf-mj@aleholm.savsjo.se:Dear subscriber
96bf-sj@aleholm.savsjo.se:Dear subscriber
96bf-ss@aleholm.savsjo.se:Dear subscriber
BRRA@hotmail.com:Dear subscriber

From this format:

Bjorn.nilsson@n.lrf.se
Carola.Fagerwall@itutb.kiruna.se
EKI7029@jack.got.kth.se
EKI7031@jack.got.kth.se
ERAGOKU@gaera.ericsson.se
Helen.Akerstrom@itutb.kiruna.se

2. The second script convert a file in this format:

jonas@home.se:Dear subscriber
96bf-mj@aleholm.savsjo.se:My name2
96bf-sj@aleholm.savsjo.se:John doe
96bf-ss@aleholm.savsjo.se:my name

to this format:

[Begin]
&email=jonas@home.se&name=Dear subscriber
&email=96bf-mj@aleholm.savsjo.se&name=My name2
&email=96bf-sj@aleholm.savsjo.se&name=John doe

Thanks in Advance!
0
Comment
Question by:jonasm
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
9 Comments
 

Author Comment

by:jonasm
ID: 1295986
Adjusted points to 250
0
 
LVL 3

Accepted Solution

by:
q2guo earned 300 total points
ID: 1295987
First Script
-----------------------------------------------------------

#!/usr/local/bin/tclsh

if {$argc !=2} {
      error "Usage: firstscript infileName Outfilename"
}

set fin [open [lindex $argv 0] r]
set fout [open [lindex $argv 1] w]
set a :Dear Subscriber

while {[gets $fin line] >= 0} {
      set line $line$a
      puts $fout $line
}
close $fout
close $fin

-------------------------------------------------------------

Second Script

-------------------------------------------------------------
#!/usr/local/bin/tclsh

if {$argc !=2} {
      error "Usage: firstscript infileName Outfilename"
}

set fin [open [lindex $argv 0] r]
set fout [open [lindex $argv 1] w]
set a \&email\=
set b \&name\=

while {[gets $fin line] >= 0} {
      regsub -all : $line \n line
      set c [lindex $line 0]
      set d [lindex $line 1]
      set line $a$c$b$d
      puts $fout $line
}
close $fout
close $fin

-------------------------------------------------------------

Both of these scripts are written in TCL.  Hope they help.

Terry
0
 
LVL 3

Expert Comment

by:q2guo
ID: 1295988
Just one small change to the above code
in the first script
the line

set a :Dear Subscriber

should read

set a ":Dear Subscriber"


Also, the first line of both scripts contains the path
to your TCL program.  It may not be what wrote above

Good luck
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:jonasm
ID: 1295989
Just a little thing in the second script.. When handling raws like:
jonas@home.se:Dear subscriber

It reurns:
&email=jonas@home.se&name=Dear

It should be like:
&email=jonas@home.se&name=Dear subscriber

Any idears?

Increased the points just as a little bonus ;-)



0
 
LVL 3

Expert Comment

by:q2guo
ID: 1295990
Sorry, my mistake

here 's it again

--------------------------------------------

#!/usr/local/bin/tclsh

if {$argc !=2} {
       error "Usage: firstscript infileName Outfilename"
}

set fin [open [lindex $argv 0] r]
set fout [open [lindex $argv 1] w]
set a \&email\=
set b \&name\=

while {[gets $fin line] >= 0} {
     regsub -all : $line \n line
     set c [lindex $line 0]
     regsub -all $c $line \0 line
     regsub -all \n $line \0 line
     set line $a$c$b$line
     puts $fout $line
}

close $fout
close $fin
0
 
LVL 3

Expert Comment

by:braveheart
ID: 1295991
If I ever get a spam starting with "Dear Subscriber", I shall come looking for you...
0
 

Author Comment

by:jonasm
ID: 1295992
One more thing with the second script.. In the begining
of the result there must be a "[Begin]" (see the begining)here is a example:

[Begin]
&email=jonas@home.se&name=Dear subscriber
&email=96bf-mj@aleholm.savsjo.se&name=My name2
&email=96bf-sj@aleholm.savsjo.se&name=John doe


Adjusted the points a bit coz of my lazyness..

/Jonas
0
 
LVL 3

Expert Comment

by:q2guo
ID: 1295993
script two again

--------------------------------------------
#!/usr/local/bin/tclsh

if {$argc !=2} {
  error "Usage: firstscript infileName Outfilename"
}

set fin [open [lindex $argv 0] r]
set fout [open [lindex $argv 1] w]
set a \&email\=
set b \&name\=

puts $fout \[begin\]

....

close $fout
close $fin
0
 

Author Comment

by:jonasm
ID: 1295994
Worked Well thanks!!


0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
repeateFront java challenge 31 95
Installing Microsoft R server on REDHAT or SUSE Linux 4 152
sum67 challenge 35 116
canBalance challenge 34 105
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question