Solved

2 text converting script..

Posted on 1998-02-10
9
274 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
Comment Utility
Adjusted points to 250
0
 
LVL 3

Accepted Solution

by:
q2guo earned 300 total points
Comment Utility
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
Comment Utility
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
 

Author Comment

by:jonasm
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 3

Expert Comment

by:q2guo
Comment Utility
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
Comment Utility
If I ever get a spam starting with "Dear Subscriber", I shall come looking for you...
0
 

Author Comment

by:jonasm
Comment Utility
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
Comment Utility
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
Comment Utility
Worked Well thanks!!


0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Process filename extension 3 154
Looking for a specific application/software 2 91
maxBlock challenge 30 99
has22 challenge 11 70
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…
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.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

762 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now