Solved

2 text converting script..

Posted on 1998-02-10
9
275 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 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
How our DevOps Team Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

825 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