Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert or Append characters to each line

Status
Not open for further replies.

joeb5110

Technical User
May 8, 2009
42
US
I use Zoc Rexx, so the question may be more specific to Zoc. Is there a way to insert or append characters to each line as data is captured? I want to add the <br> symbol so there will be line breaks when viewing the output in a browser. I used Notepad++ to quickly insert <br> down the first column, but it's a manual step I need to complete before anyone views the file.
Thanks.
 
IMHO, you should read the original file and create new with the corrected lines.
i.e
for every line in the original file
append break to the end of line
write changed line to the new file

At end rename the files
 
I don't know ZOC REXX, but the following example shows how to do it with ooREXX and Regina:

insert_br.rex
Code:
[COLOR=#0000ff]/* check REXX-version */[/color]
[COLOR=#804040][b]parse upper version[/b][/color] rexx_version
[COLOR=#0000ff]/* set specific option for Regina */[/color]
[COLOR=#804040][b]if[/b][/color] [COLOR=#008080]pos([/color][COLOR=#ff00ff]"REGINA"[/color][COLOR=#804040][b],[/b][/color] rexx_version[COLOR=#008080])[/color] [COLOR=#804040][b]>[/b][/color] 0 [COLOR=#804040][b]then[/b][/color] [COLOR=#804040][b]do[/b][/color]
  [COLOR=#0000ff]/* Don't show meessages when system commands fail */[/color]
[COLOR=#804040][b]  trace O[/b][/color]   [COLOR=#0000ff]/* Turns off all tracing */[/color]
[COLOR=#804040][b]end[/b][/color]

[COLOR=#0000ff]/* get filename from program argument */[/color]
[COLOR=#804040][b]parse arg[/b][/color] input_file
[COLOR=#804040][b]if[/b][/color] input_file [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]""[/color] [COLOR=#804040][b]then[/b][/color] [COLOR=#804040][b]do[/b][/color]
  [COLOR=#804040][b]say[/b][/color] [COLOR=#ff00ff]"usage: rexx insert_br.rex <filename>"[/color]
  [COLOR=#804040][b]exit[/b][/color]
[COLOR=#804040][b]end[/b][/color]

[COLOR=#0000ff]/* check if input_file exists */[/color]
[COLOR=#ff00ff]"DIR"[/color] input_file [COLOR=#ff00ff]">NUL 2>&1"[/color]
[COLOR=#804040][b]if[/b][/color] [COLOR=#6a5acd]RC[/color] [COLOR=#804040][b]<>[/b][/color] 0 [COLOR=#804040][b]then[/b][/color] [COLOR=#804040][b]do[/b][/color]
  [COLOR=#804040][b]say[/b][/color] [COLOR=#ff00ff]"file '"[/color] [COLOR=#804040][b]||[/b][/color] input_file [COLOR=#804040][b]||[/b][/color] [COLOR=#ff00ff]"' was not found !!!"[/color]
  [COLOR=#804040][b]exit[/b][/color]
[COLOR=#804040][b]end[/b][/color] 

output_file [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]"new_"[/color] [COLOR=#804040][b]||[/b][/color] input_file

[COLOR=#0000ff]/* Open output for writing */[/color]
[COLOR=#804040][b]call [/b][/color][COLOR=#008080]lineout[/color] output_file[COLOR=#804040][b],[/b][/color] [COLOR=#804040][b],[/b][/color] 1

[COLOR=#0000ff]/* Read lines in loop and process them */[/color]
[COLOR=#804040][b]do [/b][/color][COLOR=#804040][b]while[/b][/color][COLOR=#804040][b] [/b][/color][COLOR=#008080]lines([/color]input_file[COLOR=#008080])[/color] [COLOR=#804040][b]<>[/b][/color] 0
  [COLOR=#0000ff]/* read line from input file */[/color]
  line [COLOR=#804040][b]=[/b][/color] [COLOR=#008080]linein([/color]input_file[COLOR=#008080])[/color]
  [COLOR=#0000ff]/* create new line with <br> at end */[/color]
  line [COLOR=#804040][b]=[/b][/color] line [COLOR=#804040][b]||[/b][/color] [COLOR=#ff00ff]"<br>"[/color]
  [COLOR=#0000ff]/* write line to output file */[/color]
  [COLOR=#804040][b]call [/b][/color][COLOR=#008080]lineout[/color] output_file[COLOR=#804040][b],[/b][/color] line
[COLOR=#804040][b]end[/b][/color]
[COLOR=#0000ff]/* close all files */[/color]
[COLOR=#804040][b]call [/b][/color][COLOR=#008080]lineout[/color] output_file
[COLOR=#804040][b]call [/b][/color][COLOR=#008080]lineout[/color] input_file

[COLOR=#0000ff]/* At end rename the files */[/color]
input_file_old [COLOR=#804040][b]=[/b][/color] input_file [COLOR=#804040][b]||[/b][/color] [COLOR=#ff00ff]".old"[/color] 

[COLOR=#0000ff]/* check if old file exists */[/color]
[COLOR=#ff00ff]"DIR"[/color] input_file_old [COLOR=#ff00ff]">NUL 2>&1"[/color]
[COLOR=#0000ff]/* when exists, then delete it */[/color]
[COLOR=#804040][b]if[/b][/color] [COLOR=#6a5acd]RC[/color] [COLOR=#804040][b]=[/b][/color] 0 [COLOR=#804040][b]then[/b][/color] [COLOR=#804040][b]do [/b][/color]
  [COLOR=#ff00ff]"DEL"[/color] input_file_old
[COLOR=#804040][b]end[/b][/color]

[COLOR=#0000ff]/* rename original file to *.old */[/color]
[COLOR=#ff00ff]"REN"[/color] input_file  input_file_old
[COLOR=#0000ff]/* rename new file to original */[/color]
[COLOR=#ff00ff]"REN"[/color] output_file input_file

[COLOR=#804040][b]exit[/b][/color]
Now, for given example data file
data.htm
Code:
1
2
hallo

that's all
after running the script with
Code:
rexx insert_br.rex data.htm
or
Code:
rexx insert_br.rex data.htm
we get as result the modified file
data.htm
Code:
1<br>
2<br>
hallo<br>
<br>
that's all<br>
and the original data file renamed to data.htm.old
 
Correct the typo:
You can run the script above with
Code:
rexx insert_br.rex data.htm
and/or
Code:
regina insert_br.rex data.htm
 
clip= ZocClipboard("READ")
clip= clip"^M"
Call ZocSend ""clip||""

this is a simple script to take what you have on the clipboard and add enter to the end.

cr= x2c(0d)
lf= x2c(0a)
crlf= cr||lf

you can use CR or LF or both to replace the ^M which as i understand is just enter.

if your using an array of line just change clip to line and ignore the 1st line as thats just to read from the clipboard
 
Thank you for the replies. I'll see how these suggestions work out.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top