|
Answer» I've been lurking here for a while and have picked up some great tips, but I'm stuck on something and hoped someone could help.
Once a month I copy a file off our Unisys Clearpath Enterprise Server "aka" MAINFRAME and send the file off and retrieve a file in return. The problem is that the file I send them cannot have trailing spaces and it does. The solution cannot be solved server side as the program that creates the file does not have the functionality to strip the spaces. The old file transfer utility we used had the option of stripping the spaces, but our current one does not. I know that I can solve the problem by just opening the text file once it is copied and saving it again with a text editor that has the functionality to strip trailing spaces, but it would be nice if I could TAKE care of it within a batch file as everything else within this PROCESS is currently done by batch file.
Here is a sampling of what the file contains: $6277 VU080229CDARS VU080229XXXXX 20 VU080229SD1999HA VU080229SD1999JD VU080229SD1999PF VU080229SD1999UF VU080229SD1999YG VU080229SD2990CU VU080229SD2990EN VU080229SD2990FV VU080229SD2990HZ
So what I would like is possibly a For statement that would pipe each line of my file into another file without the trailing spaces, but some of the lines are going to have a space inbetween characters. The output text I receive back looks like the following (it has other stuff ALSO, but due to sensitivity of the content I deleted it).
V U 080229 SD1999UF,E53 V U 080229 SD1999YG,E53 V U 080229 SD2990CU,E53 V U 080229 SD2990EN,E53 V U 080229 SD2990FV,E53 V U 080229 SD2990HZ,E53 V U 080229 SD2990KY,E53 V U 080229 SD2990QG,E53 V U 080229 SD2990SQ,E53
So the max length of my input is going to be 16 characters. Is it possible to have a For statement that will take the first 16 characters of each line and then pipe it to another file? The last line of the file I send is just an 'x' so that could tell it to stop.
If anyone has any ideas I would be appreciative. Thanks
Quote from: shiftyness on March 03, 2008, 05:38:18 PM Is it possible to have a For statement that will take the first 16 characters of each line and then pipe it to another file?
Yes. The easiest way I can think of would be something like:
Code: [Select]echo off setlocal enabledelayedexpansion for /f "tokens=*" %%a in (sample1.txt) do ( set line=%%a echo !line:~0,16!>>sample2.txt )This ASSUMES the original sampling file is sample1.txt and the file you get back is to be sample2.txt. You will also need to clear out the contents of sample2.txt between runs if you run multiple times in the same directory as it will keep appending to the end. Or if you really wanted to shorten the FOR into one line (you still need the enabledelayedexpansion), you can try:
Code: [Select]setlocal enabledelayedexpansion for /f "tokens=*" %%a in (sample1.txt) do (set line=%%a&echo !line:~0,16!>>sample2.txt)
|