1.

Solve : Move end of line marker in every line to a specific column?

Answer»

Hello,

Could you please give me pointers on how to code a batch script to read every line in a text file and move the end of line marker to a SPECIFIC column? I have hundreds of files which require this formatting.

Input: ABCDEFGHI
Output: ABCDEFGHI

Appreciate your inputs.

Thanks. Code: [SELECT]type "file.txt" |repl "(.*)" "$1                          " |repl "^(.{22}).*" "$1"
This uses a helper batch file called `repl.bat` (by dbenham) - download from:  https://www.dropbox.com/s/qidqwztmetbvklt/repl.bat

Place `repl.bat` in the same FOLDER as the batch file or in a folder that is on the path.


In the command line above the number 22 in the last term tells it where to put the new line - here it is after the 22nd character on each line.
If you need more than the 25th column then add more spaces after the first $1 (there are 25 spaces there at the MOMENT).

Thank you. I will try this.

One more question. In CASE of a varying column (say the new line is present in column 10 on line 1 and column 15 on line 2)
How do i capture the current position/column of the new line character? I can insert the appropriate no of spaces in between and move the new line character to the specific column.

Thanks.The code moves it to the end of the 22nd column in all lines, and pads the lines with spaces if needed.



Discussion

No Comment Found