shell - Batch Script to manipulate an existing textfile -
I'm totally new to writing a batch script, I'm busy with a tutorial in the example below. Can i learn I really need help writing a batch script to insert a line of text between the existing text file.
For example, the file with myfile.txt file is given:
A BCD FAG HJClnamnop Q RS T Uvuxiz Command ./path-in-middle.sh "=== === ===" myfile.txt should modify this file:
A BCD efg hjiklmnop === === === q rs t uvwxyz
Calculate the number of files with FIND / F %% in the line for @echo off rem file (get the "Search / C / V" line "set number / one middle = numlines / 2 Find all the lines in the rim process, insert line numbers using FINDSTR / N / F "token = 1 * delims =:" %% in ('findstr / n' ^ ""% 2 ') (RAM) Echo root line is echo / %% b rem if line is middle one ... if %% is equal to% mid% (resonance% ~ 1 to new line)) previous batch file Create as - middle-middle .bat and execute it as follows:
put-in-middle "=== === === "Myfile.txt Note:
- Previous program Does not check Ion, such as missing parameter if you wish, this investigation may also be included.
- If the row is empty, then slash
echo / %% b is inserted in order to avoid the "ECHO is turned on" message. If in the line "/?" If the string can occur, then this command should be changed to echo (%% b ) so that a single help can be displayed in this case (the left parenthesis is the only character
if the file There are special characters in batch, such as < , echo / %% b command failed In this case, special processing of file lines Should be added. The same point applies to the newly inserted line.
The previous program only displays the new file in the screen. If you want to change the original file, then the output should be redirected to a support file and change the original one to the end: .
(for / for "token = 1 * deals =:" %% a in ('findstr / n' ^ "% 2 ') (... ..)) & Gt; Auxiliar.txt move / u auxiliar.txt% 2
Comments
Post a Comment