|
-
Oct 3rd, 2019, 12:35 PM
#1
Thread Starter
Hyperactive Member
Insert characters at particular position via batch file
Hello, I´m looking for if it´s possible to insert characters ("ORA") at every 5th place into textfile via CMD script. So output should looks like this: 212čORAýá2vORAéé etc. I´ve looked at many ways how to do that, but none of these works for me. Could you help me?
-
Oct 3rd, 2019, 01:12 PM
#2
Re: Insert characters at particular position via batch file
Have the cmd script call a program you write to do it?
If you had a version of Sed that ran on windows, then perhaps it could be scripted, but I'm not sure about that.
"Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930
-
Oct 8th, 2019, 12:22 PM
#3
Thread Starter
Hyperactive Member
Re: Insert characters at particular position via batch file
Sorry if I misled you. By CMD, I mean directly using cmd commands.
-
Oct 8th, 2019, 02:07 PM
#4
Re: Insert characters at particular position via batch file
I understood what you meant.
If you open a cmd window and type help, you'll get a list of all the commands the cmd interpreter knows.
As I said, there is no type of stream editor which could read a file in, operate on it, and put it back out.
There are such things in other Operating systems, by the fact that there are applications written that can take redirected input, operate on it, and redirect the output back to a file.
The cmd interpreter supports redirection, although I think in a less efficient way than Linux, but you would still need an application that can take the input, modify it, and output it.
Since there isn't anything that I know of written to do that, then you would have to write your own. In either case, it isn't something directly support by the shell, but by applications run in the shell.
Also, your example is not inserting the data at every fifth position, at least not every fifth position of the input, but rather after every fourth character of the input.
I think of every 5th position as being position 5, 10, 15 , 20, etc... but your example puts the string before position 5, 9, 13, 17, of the input.
That is why I think if that is what you want to do, you don't want to do that in the cmd interpreter, but rather than in code you write, which could be called from the cmd interpreter.
The code would be a fairly simple loop, the pseudo code being along the lines of.
Code:
Open the file to be read.
Open a file to be output.
While there are four or more characters left in the input
Read four characters from the input
Write the four characters to the output
Write "ORA" to the output
Loop
If there are any characters left in the input (should be three or less)
Write them to the output
End If
Close the Output
Close the Input
You could also rename the Input if you want to save it, and rename the Output to the Input file name, if that is what you want.
"Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|