I am looking for help in the batch file command to delete all text on a single line after a certain word is found.
Example text:
IMAD: 20170614L1B78J1C000441
I would like to delete all of the text after "IMAD:" so that this only remains on the line.
I tried to use this code but it doesn't work:
for /f "tokens=1 delims=IMAD:" %%a in (didigetit.txt) do (echo %%a >>newfilename.txt)
Any help is GREATLY appreciated!!
Batch file command to delete all text after certain word
Moderator: DosItHelp
-
- Posts: 2
- Joined: 14 Jun 2017 12:37
Re: Batch file command to delete all text after certain word
Hi
To be more clear for us :
Just provide an example of the input file and what did you expect as ouput file !
Thanks !
To be more clear for us :
Just provide an example of the input file and what did you expect as ouput file !
Thanks !
Re: Batch file command to delete all text after certain word
Hello there .o/
Do some restrictions such as "I cannot use any exe that doesn't ship with Windows" apply?
If not, I'd just use a win32 port of the sed command (which you can get from here: http://gnuwin32.sourceforge.net/packages/sed.htm ).
You could use it like so:
If you can't use third party executables, it certainly still can be done, but I think you might need to know for sure of a character that will never, ever appear in your input file, to use as a delimiter.
Do some restrictions such as "I cannot use any exe that doesn't ship with Windows" apply?
If not, I'd just use a win32 port of the sed command (which you can get from here: http://gnuwin32.sourceforge.net/packages/sed.htm ).
You could use it like so:
Code: Select all
type your_input_file | sed s/"^IMAD:.*"/"IMAD:"/ > your_output_file
If you can't use third party executables, it certainly still can be done, but I think you might need to know for sure of a character that will never, ever appear in your input file, to use as a delimiter.
Re: Batch file command to delete all text after certain word
If such restrictions (Lachdanan has mentioned) apply, then you could use the hybrid JScript/batch script JREPL.BAT created by Dave Benham.
Depending on the answer to the question of Hackoo, it might also be possible to use variable repalcement only.
penpen
Depending on the answer to the question of Hackoo, it might also be possible to use variable repalcement only.
penpen
-
- Posts: 2
- Joined: 14 Jun 2017 12:37
Re: Batch file command to delete all text after certain word
Sorry for the delay getting back on, was on family vacation last week. Yes to answer your question, I am limited to Windows Server programs only to accomplish this. Ideally I would like to not use that particular line as my column delimiter and instead add both row and column delimiters to my text file. That having been said, the original text is a bank wire detail report with multiple "garbage" lines that I strip down to only the essential lines with specified items I need for my data import into MS SQL. I use the find function for these essentials and output results into a temp txt file. Then I run the jrepl.bat program to strip out empty white spaces and then output the clean results into another temp file. This particular line above I thought I could use as a row delimiter for the SQL import but upon further review of the end result file, now I see that this particular word is not a constant in every group of wire detail results. So, my desired result would be a batch file that I can use where at the end of each line I put a row delimiter and at the end of each group I insert a column delimiter.