?
Solved

2 text converting script..

Posted on 1998-02-10
9
Medium Priority
?
283 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
  • 4
  • 4
9 Comments
 

Author Comment

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

Accepted Solution

by:
q2guo earned 1200 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
Industry Leaders: 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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

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. …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses
Course of the Month15 days, 21 hours left to enroll

850 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