?
Solved

2 text converting script..

Posted on 1998-02-10
9
Medium Priority
?
279 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 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses
Course of the Month9 days, 5 hours left to enroll

765 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