Solved insert a carriage return into a txt file

July 6, 2010 at 13:01:56
Specs: Windows XP

Hi all.
I believe I have a challenge for you all today.
Basically I just need to insert a carriage return into a txt file before a certain (known ) string using a .bat file. Basically the txt file has about 2000 records clumped together. The findstr would be perfect as I am looking for the reference number of the user, but the findstr just returns the entire file as there are no carriage returns. I need to insert a carriage return before every instance of the word “header” and after every instance of the word “MTR”.If I can get the carriage return in those places it would be great because the findstr will return every bit of the record between the “Header” and “MTR”.
However as easy as this may sound there are a few catches.
1. there are currently no carriage returns in the file.
2.The file is about 70mb
3.Although there are delimiters in the file, the actual number of delimiters changes per record and is always well above the 26 allowed by tokens.
4.there are a huge number of lines (over 2000 a4 pages) worth of records, using a loop would be inpractable ?
5.Findstr just returns the entire txt file because there are no carriage returns
6.There are about 2000 instances of the word “header”

Sample format
Header’there is just so’much text that : goes here and the ‘amount of dilimiters’? is just socrazy’the RECORD NUMBER MAYBE BOUT HERE+and then there would be more stuff.This∧ the dilimiters would:go on a further+50lines’before it hits the’MTR’Header:and were off again for another record of 50 lines’MTR
The final appearance (if possible to export into a .txt file with changes ?) it to look like the below as the find str will grab everything between the “header” and “MTR”.the RECORD NUMBER will be based on user input but I can do that.Here is what im hoping for

Header’there is just so’much text that : goes here and the ‘amount of dilimiters’? is just socrazy’the RECORD NUMBER MAYBE BOUT HERE+and then there would be more stuff.This∧ the dilimiters would:go on a further+50lines’before it hits the’MTR’

Header’there is just so’much text that : goes here and the ‘amount of dilimiters’? is just socrazy’the RECORD NUMBER MAYBE BOUT HERE+and then there would be more stuff.This∧ the dilimiters would:go on a further+50lines’before it hits the’MTR’

Header’there is just so’much text that : goes here and the ‘amount of dilimiters’? is just socrazy’the RECORD NUMBER MAYBE BOUT HERE+and then there would be more stuff.This∧ the dilimiters would:go on a further+50lines’before it hits the’MTR’

Thanks a million if you can help


See More: insert a carriage return into a txt file

Report •


✔ Best Answer
July 7, 2010 at 13:58:55

Option Explicit
Const magicStr = "'header="

If WScript.Arguments.Count = 0 Then
  MsgBox "No Arguments; aborting", vbCritical, WScript.ScriptName
  WScript.Quit 1
End If
Dim fso, fIn, fOut, buff, peek, arg, strLen
Set fso = CreateObject("Scripting.FileSystemObject")
strLen = Len(magicStr) - 1

For Each arg In WScript.Arguments
  peek = ""
  Set fIn  = fso.OpenTextFile(arg)
  Set fOut = fso.OpenTextFile(fso.GetBaseName(arg) & ".out." _
    & fso.GetExtensionName(arg), 2, True)

  Do Until fIn.AtEndOfStream
    buff = peek & fIn.Read(4096)
    If Not fIn.AtEndOfStream Then
      peek = fIn.Read(strLen)
    Else
      peek = ""
    End If
    buff = Replace(buff & peek, magicStr, vbNewLine & magicStr)
    fOut.Write Left(buff, Len(buff) - Len(peek))
  Loop
  fOut.Write peek
Next 'arg
MsgBox "Done", vbOKOnly, WScript.ScriptName



#1
July 6, 2010 at 13:52:32

Try looking at the file and see if the dump is using a strange character for line breaks. If it's only using "\n" or "\r" instead of "\n\r", then it's an easy fix. Also, if each record is guaranteed to be X characters long, it's also easy to fix.

Report •

#2
July 6, 2010 at 14:01:21

Hi Razor.The problem is that there are no line breaks at all.I must have been thinking wrong when I said carriage returns, I meant line breaks.Basicly the file is one big huge 2000 page single line :(.The record will be different each time, but will always have "header" at the start of the record and "MTR" at the end.I was thinking of find and replace ie find :"Header" and replace with header \n ?, that type thing ?

actually just re-read that and confused myself. Basicly it's one long dump with no line breaks or anything.I need to find the word "Header" and insert a line break before every instance of this word. Hope this helps ?


Report •

#3
July 6, 2010 at 21:36:14

i think you're sunk if you're restricted to native batch. vbscript (native to windows) could handle it with facility, using stdin.read method to get "bites" of the file, then test for each "frame" if matches your specs. Let me know if interested. (I don't want to work on it only to have "it must be native BATCH script ONLY").

Report •

Related Solutions

#4
July 7, 2010 at 00:02:27

Hi nbrane . Could it be VB that word use's as there are loads and loads of restrictions on the computer, or even an Icon I can just run ?,I'm not sure if I can run a VB macro outside of word thou. What kind of way would you think is best ?

Report •

#5
July 7, 2010 at 00:33:08

Are you limited to built-in Windows utilities for this???

You can do this w/ SED (unix utility) - which is available for Windows w/ the unixutils package ( http://unxutils.sourceforge.net/ )

Basically if the word you wanted to split on was 'header', you'd use:

s/header/\\
/g

DOS probably won't handle the linebreak though, so you need to save that as a file & run it in sed with -f

It's a single command to do that w/ sed (built into a any linux machine if you can get access to one)

Or like the other poster said, you could use VB / .NET to do this, but I would use something like the split() command in perl to split the string into an array by your key & then just loop through the array & write it out with line breaks.


Report •

#6
July 7, 2010 at 02:01:07

Hi fmwap.I am limited to whats built into windows sadly enough :(. Really all I need is a bit of code to insert a line break after each instance of the word "Header". I can do this in MSword using find and replace and the "^l" but I would just rather an automated way to do it, as it will have to be done every day as new records are added daily.
I do have a macro in MSword for this, but not sure how to use the macro outside of MSword.
Using a batch would be the holy grail, but beggers can't be chosers :(

Report •

#7
July 7, 2010 at 02:20:05

Actually I havent been clear of this. Everyday I use a .bat to group all the data files (.txt files) together into one big .txt file which makes it easy to find what im looking for.

However what im trying to do now is simply filter the info.So I enter the record number into a .bat file. The .bat file finds the record number and returns everything between the "header" and "mtr" of that particular record, and then keeps looking incase there are more instances or amendments to the record. The problem is because there are no line breaks the findstr is returning the whole document rather than just the the required record. Not sure if this helps ?


Report •

#8
July 7, 2010 at 05:20:59

Everyday I use a .bat to group all the data files (.txt files) together into one big .txt file which makes it easy to find what im looking for.
How are you doing that, and just how many records are in each file?

EDIT: To clear up what is/isn't native to Windows, you have three scripting languages that install with WinXP. They are batch scripts, VBScripts, and JScripts. If you have Win7, you also have POWERSHELL!, but you don't, so there you go.


Report •

#9
July 7, 2010 at 05:31:11

FWIW, PowerShell! for Windows Vista, XP and Server 2003:
Windows PowerShell

Insomniac at large


Report •

#10
July 7, 2010 at 05:42:25

Hi Boys. I can't download anything onto the computer as they are restricted access :(. I use the copy file1.txt+ffile2.txt+file3.txt > master.txt

This appends all the files into one as the record could be in any file so instead of searching 3 files.(Actually there is a new file created everyday so it appends them into the one big one. I now have them in one file. The would be about 500 records in each file every day. I can't use the powershell as im not allowed download anything. Can I use a VBmacro outside of word for a word file. I ie, I can export the master.txt file to a .doc file instead and then run a VB macro against the .doc file ?


Report •

#11
July 7, 2010 at 06:31:41

You're confusing Visual Basic for Applications and Visual Basic Script. they're separate languages with similar names. And yes, you could run a VBScript on a text file. You can also run a VBA macro on a text file, but that requires Word (or some other MS Office program) to be open.

Report •

#12
July 7, 2010 at 06:36:50

Well at this stage I will take any help or sugestions or code that can in anyway help.Floor is open lads, no wrong answers. Can you advise how I could run a VBScript on a text file ?, I.e do I make it in note pad and save as a .vbf or what ever extension.
Any ideas at all will help. I don't need the search for record function, I just need the line break code.Maybe I can even call the VBscript from a .bat so it's still a one click for the user ?

Report •

#13
July 7, 2010 at 08:12:05

Just wondering, but what's generating these text files? And why isn't it adding something between records?

Report •

#14
July 7, 2010 at 08:15:02

I use the copy file1.txt+ffile2.txt+file3.txt > master.txt

Could you create a text file with only a cr/lf in it, and include it in your copy command before all the data files?

copy file1.txt+crlf.txt+file2.txt+crlf.txt+file3.txt > master.txt

I'm actually surprised the copy file+... doesn't inject a cr/lf after each file anyway, making the contents of the files a record on a new line of master.txt. I was experimenting with both copy and type (looping through txt files), and came up with nearly identical "master" files:

@ECHO OFF
SETLOCAL

SET file_list=
FOR /R "%usrtmp%\Your\Path\To" %%a IN (21856_*.txt) DO (
    SET file_list="%%a"+!file_list!
    TYPE "%%a" >>"%usrtmp%\Your\Path\To\21856.Type.Master.txt"
)
SET file_list=!file_list:~0,-1!
COPY !file_list! "%usrtmp%\Your\Path\To\21856.Copy.Master.txt"

EXIT /B

EDIT: Sorry - it was the way I generated my test data. It had cr/lf in each of the files.

This will create line breaks after each file, with crlf.txt being a file
I opened with notepad and hitting <enter>:

@ECHO OFF
SETLOCAL

SET file_list=
FOR /R "%usrtmp%\Your\Path\To" %%a IN (21856_*.txt) DO (
    SET file_list=!file_list!+"%%a"+"%usrtmp%\Your\Path\To\crlf.txt"
    >>"%usrtmp%\Your\Path\To\21856.Type.Master.txt" TYPE "%%a" 
    >>"%usrtmp%\Your\Path\To\21856.Type.Master.txt" TYPE "%usrtmp%\Your\Path\To\crlf.txt" 
)
SET file_list=!file_list:~1!
COPY !file_list! "%usrtmp%\Your\Path\To\21856.Copy.Master.txt"

EXIT /B

Insomniac at large


Report •

#15
July 7, 2010 at 08:45:27

Ok a few answers to your questions
Razor2.3 :
1) The files come from different sources, and they just send them as a dump.I tried to get them to insert the line break but no go.

Orangeboy
2) copy file1.txt+crlf.txt+file2.txt+crlf.txt+file3.txt > master.txt
wont work because I need the line breaks in the file 1.txt not between the files in the master.txt, i.e no need for gaps between the insertion of files, I need the gaps before a recurrance of the string "header".The is a occurance of the word header about 200 times per file, so its not just one per file .I mearly merge the files as it makes it easier to search.

3)I think the above code is inserting line breaks to break up the actual files rather than the contents. What I actually need is line breaks in the actuall contents of each file.

So lets just assume I have one file called master.txt and need to insert a line break after every occurance of the word Header(about 2000 occurances of word header). The fact that the files are merged dosn't really matter as the end result is still one big file.

I really appracaite all this help, I honestly do, but Im not sure if you guys understand what im trying to do. It's like the file master.txt has may occurances of the word header.
1.I need to insert a line break before every occurance of the word "header" in the master.txt file

2.Any code that is built into windows XP is cool, what ever you think is the best,but I can't download anything :(.

3.This code will be run every dayso thats why a .bat would be cool, but we can manually click on it (i.e it shoulden't auto run at a certan time every day, we can run t ourselfs.


Report •

#16
July 7, 2010 at 09:53:31

Okay, final question: Can we see the first 10 records or so? There seems to be some inconsistency in your example.
If you don't mind showing me, but don't want to show everyone, you can PM me the data, or PM me asking for an email address.

Report •

#17
July 7, 2010 at 10:17:55

I don't have the actual example on my now as it's in work. I will simulate and example thou.Hold one.

Report •

#18
July 7, 2010 at 10:22:05

Sample of file1.txt Note that there are serveral occurances of the word HEADER in the below dump. In the actual file there would be about 200 occurances in each file, below has 6 occurances.

‘header:text fgaujfg asdfgasdgf iasdgffguiehf ifg izbgzsbv izs: fgayudg fadugf u’dfasdDFAHFIKAWE’DFGAD:OASFUI DFJASDGFUSD’dugfadjfgasdgf:djkagfjdksgf igfujd RECORD NUMBER:iyudfguadfgc uadfadufgvyuedgf’daifgadg fdjhfguasd fuabgfuabgfadb f’dhfuidgsafgdafgy dui gfuaygfa iydfg difgiagfia dohauihasfghau ::duigfg+dygfjhasdgfjhyadg dagfujadgfsdh?jhcgvufgc yud fddacdyi tyd:sjhgfadgfad’sdgasudg fihdaf hadifcdyugadgf fuidtext fgaujfg asdfgasdgf iasdgffguiehf ifg izbgzsbv izs: fgayudg fadugf u’dfasdDFAHFIKAWE’DFGAD:OASFUI DFJASDGFUSD’dugfadjfgasdgf:djkagfjdksgf igfujd RECORD NUMBER:iyudfguadfgc uadfadufgvyuedgf’daifgadg fdjhfguasd f’’uabgfuabgfadb f’dhfuidgsafgdafgy dui gfuaygfa iydfg difgiagfia dohauihasfghau ::duigfg+dygfjhasdgfjhyadg dagfujadgfsdh?jhcgvufgc yud fddacdyi tyd:sjhgfadgfad’sdgasudg fihdaf hadifcdyugadgf fuidtext fgaujfg asdfgasdgf iasdgffguiehf ifg izbgzsbv izs: fgayudg fadugf u’dfasdDFAHFIKAWE’DFGAD:OASFUI DFJASDGFUSD’dugfadjfgasdgf:djkagfjdksgf igfujd RECORD NUMBER:iyudfguadfgc uadfadufgvyuedgf’daifgadg fdjhfguasd fuabgfuabgfadb f’dhfuidgsafgdafgy dui gfuaygfa iydfg difgiagfia dohauihasfghau ::duigfg+dygfjhasdgfjhyadg dagfujadgfsdh?jhcgvufgc yud fddacdyi tyd:sjhgfadgfad’sdgasudg fihdaf hadifcdyugadgf fuid’MTR‘header:text fgaujfg asdfgasdgf iasdgffguiehf ifg izbgzsbv izs: fgayudg fadugf u’dfasdDFAHFIKAWE’DFGAD:OASFUI DFJASDGFUSD’dugfadjfgasdgf:djkagfjdksgf igfujd RECORD NUMBER:iyudfguadfgc uadfadufgvyuedgf’daifgadg fdjhfguasd fuabgfuabgfadb f’dhfuidgsafgdafgy dui gfuaygfa iydfg difgiagfia dohauihasfghau ::duigfg+dygfjhasdgfjhyadg dagfujadgfsdh?jhcgvufgc yud fddacdyi tyd:sjhgfad’gfad’sdgasudg fihdaf hadifcdyugadgf fuidtext fgaujfg asdfgasdgf iasdgffguiehf ifg izbgzsbv izs: fgayudg fadugf u’dfasdDFAHFIKAWE’DFGAD:OASFUI DFJASDGFUSD’dugfadjfgasdgf:djkagfjdksgf igfujd RECORD NUMBER:iyudfguadfgc uadfadufgvyuedgf’daifgadg fdjhfguasd fuabgfuabgfadb f’dhfuidgsafgdafgy dui gfuaygfa iydfg difgiagfia dohauihasfghau ‘::duigfg+dygfjhasdgfjhyadg dagfujadgfsdh?jhcgvufgc yud fddacdyi tyd:sjhgfadgfad’sdgasudg fihdaf hadifcdyugadgf fuidtext fga’’ujfg asdfgasdgf iasdgffguiehf ifg izbgzsbv izs: fgayudg fadugf u’dfasd’DFAHFIKAWE’DFGAD:OASFUI DFJASDGFUSD’dugfadjfgasdgf:djkagfjdksgf igfujd RECORD NUMBER:iyudfguadfgc uadfadufgvyuedgf’daifgadg fdjhfguasd fuabgfuabgfadb f’dhfuidgsafgdafgy dui gfuaygfa iydfg difgiagfia dohauihasfghau ::duigfg+dygfjhasdgfjhyadg dagfujadgfsdh?jhcgvufgc yud fddacdyi tyd:sjhgfadgfad’sdgasudg fihdaf hadifcdyugadgf fuid’MTR
‘header:text fgaujfg asdfg’asdgf iasdgffguiehf ifg izbgzsbv izs: fgayudg fadugf u’dfasdDFAHFIKAWE’DFGAD:OASFUI DFJASDGFUSD’dugfadjfgasdgf:djkagfjdksgf igfujd RECORD NUMBER:iyudfguadfgc uadfadufgvyuedgf’daifgadg fdjhfguasd fuabgfuabgfadb f’dhfuidgsafgdafgy dui gfuaygfa iydfg difgiagfia dohauihasfghau ::duigfg+dygfjhasdgfjhyadg dagfujadgfsdh?jhcgvufgc yud fddacdyi tyd:sjhgfadgfad’sdgasudg fihdaf hadifcdyugadgf fuidtext fgaujfg asdfgasdgf iasdgffguiehf ifg izbgzsbv izs: fgayudg fadugf u’d’fasdDFAHFIKAWE’DFGAD’:OASFUI DFJASDGFUSD’dugfadjfgasdgf:djkagfjdksgf igfujd RECORD NUMBER:iyudfguadfgc uadfadufgvyuedgf’daifgadg fdjhfguasd fuabgfuabgfadb f’dhfuidgsafgdafgy dui gfuaygfa iydfg difgiagfia dohauihasfghau ::duigfg+dygfjhasdgfjhyadg dagfujadgfsdh?jhcgvufgc yud fddacdyi tyd:sjhgfadgfad’sdgasudg fihdaf hadifcdyugadgf fuidtext fgaujfg asdfgasdgf iasdgffguiehf ifg izbgzsbv izs: fgayudg fadugf u’dfasdDFAHFIKAWE’DFGAD:OASFUI DFJASDGFUSD’dugfadjfgasdgf:djkagfjdksgf igfujd RECORD NUMBER:iyudfguadfgc uadfadufgvyuedgf’daifgadg fdjhfguasd fuabgfuabgfadb f’dhfuidgsafgdafgy dui gfuaygfa iydf’g difgiagfia dohauihasfghau ::duigfg+dygfjhasdgfjhyadg dagfujadgfsdh?jhcgvufgc yud fddacdyi tyd:sjhgfadgfad’sdgasudg fihdaf hadifcdyugadgf fuid’MTR
‘header:text fgaujfg asdfgasdgf iasdgffguiehf ifg izbgzsbv izs: fgayudg fadugf u’dfasdDFAHFIKAWE’DFGAD:OASFUI DFJASDGFUSD’dugfadjfgasdgf:djkagfjdksgf igfujd RECORD NUMBER:iyudfguadfgc uadfadufgvyuedgf’daifgadg fdjhfguasd fuabgfuabgfadb f’dhfuidgsafgdafgy dui gfuaygfa iydfg difgiagfia dohauihasfghau ::duigfg+dygfjhasdgfjhyadg dagfujadgfsdh?jhcgvufgc yud fddacdyi tyd:sjhgfadgfad’sdgasudg fihdaf hadifcdyugadgf fuidtext fgaujfg asdfgasdgf iasdgffguiehf ifg izbgzsbv izs: fgayudg fadugf u’dfasdDFAHFIKAWE’DFGAD:OASFUI DFJASDGFUSD’dugfadjfgasdgf:djkagfjdksgf igfujd RECORD NUMBER:iyudfguadfgc uadfadufgvyuedgf’daifgadg fdjhfguasd fuabgfuabgfadb f’dhfuidgsafgdafgy dui gfuaygfa iydfg difgiagfia dohauihasfghau ::duigfg+dygfjhasdgfjhyadg dagfujadgfsdh?jhcgvufgc yud fddacdyi tyd:sjhgfadgfad’sdgasudg fihdaf ‘hadifcdyugadgf fuidtext fgaujfg asdfgasdgf iasdgffguiehf ifg izbgzsbv izs: fgayudg fadugf u’dfasdDFAHFIKAWE’DFGAD:OASFUI DFJASDGFUSD’dugfadjfgasdgf:djkagfjdksgf igfujd RECORD NUMBER:iyudfguadfgc uadfadufgvyuedgf’daifgadg fdjhfguasd fuabgfuabgfadb f’dhfuidgsafgdafgy dui gfuaygfa iydfg difgiagfia dohauihasfghau ::duigfg+dygfjhasdgfjhyadg dagfujadgfsdh?jhcgvufgc yud fddacdyi tyd:sjhgfadgfad’sdgasudg fihdaf hadifcdyugadgf fuid’MTR
‘header:text fgaujfg asdfgasdgf iasdgffguiehf ifg izbgzsbv izs: fgayudg fadugf u’dfasdDFAHFIKAWE’DFGAD:’ DFJASDGFUSD’dugfadjfgasdgf:djkagfjdksgf igfujd RECORD NUMBER:iyudfguadfgc uadfadufgvy’uedgf’daifgadg fdjhfguasd fuabgfuabgfadb f’dhfuidgsafgdafgy dui gfuaygfa iydfg difgiagfia dohauihasfghau ::duigfg+dygfjhasdgfjhyadg dagfujadgfsdh?jhcgvufgc yud fddacdyi tyd:sjhgfadgfad’sdgasudg fihdaf hadifcdyugadgf fuidtext fgaujfg asdfgasdgf iasdgffguiehf ifg izbgzsbv izs: fgayudg fadugf u’dfasdDFAHFIKAWE’DFGAD:OASFUI DFJASDGFUSD’dugfadjfgasdgf:djkagfjdksgf igfujd RECORD NUMBER:iyudfguadfgc uadfadufgvyuedgf’daifgadg fdjhfguasd fuabgfuabgfadb f’dhfuidgsafgdafgy dui gfuaygfa iydfg difgiagfia dohauihasfghau ::duigfg+dygfjhasdgfjhyadg dagfujadgfsdh?jhcgvufgc yud fddacdyi tyd:sjhgfadgfad’sdgasudg fihdaf hadifcdyugadgf fuidtext fgaujfg asdfgasdgf iasdgffguiehf ifg izbgzsbv izs: fgayudg fadugf u’dfasdDFAHFIKAWE’DFGAD:OASFUI DFJASDGFUSD’dugfadjfgasdgf:djkagfjdksgf igfujd RECORD NUMBER:iyudfguad’fgc uadfadufgvyuedgf’daifgadg fdjhfguasd fuabgfuabgfadb f’dhfuidgsafgdafgy dui gfuaygfa iydfg difgiagfia dohauihasfghau ::duigfg+dygfjhasdgfjhyadg dagfujadgfsdh?jhcgvufgc yud fddacdyi tyd:sjhgfadgfad’sdgasudg fihdaf hadifcdyugadgf fuid’MTR
‘header:text fgaujfg asdfgasdgf iasdgffguiehf ifg izbgzsbv izs: fgayudg fadugf u’dfasdDFAHFIKAWE’DFGAD:OASFUI DFJASDGFUSD’dugfadjfgasdgf:djkagfjdksgf igfujd RECORD NUMBER:iyudfguadfgc uadfadufgvyuedgf’daifgadg fdjhfguasd fuabgfuabgfadb f’dhfuidgsafgdafgy dui gfuaygfa iydfg difgiagfia dohauihasfghau ::duigfg+dygfjhasdgfjhyadg dagfujadgfsdh?jhcgvufgc yud fddacdyi tyd:sjhgfadgf’ad’sdgasudg fihdaf hadifcdyugadgf fuidtext fgaujfg asdfgasdgf iasdgffguiehf ifg izbgzsbv izs: fgayudg fadugf u’dfasdDFAHFIKAWE’DFGAD:OASFUI DFJASDGFUSD’dugfadjfgasdgf:djkagfjdksgf igfujd RECORD NUMBER:iyudfguadfgc uadfadufgvyuedgf’daifgadg fdjhfguasd fuabgfuabgfadb f’dhfuidgsafgdafgy dui gfuaygfa iydfg difgiagfia dohauihasfghau ::duigfg+dyg’fjhasdgfjhyadg dagfujadgfsdh?jhcgvufgc yud fddacdyi tyd:sjhgfadgfad’sdgasudg fihdaf ha’difcdyugadgf fuidtext fgaujfg asdfgasdgf iasdgffguiehf ifg izbgzsbv izs: fgayudg fadugf u’dfasdDFAHFIKAWE’DFGAD:OASFUI DFJASDGFUSD’dugfadjfgasdgf:djkagfjdksgf igfujd RECORD NUMBER:iyudfguadfgc ‘uadfad’ufgvyuedgf’daifgadg fdjhfguasd fuabgfuabgfadb f’dhfuidgsafgdafgy dui gfuaygfa iydfg ‘difgiagfia dohauihasfghau ::duigfg+dygfjhasdgfjhyadg dagfujadgfsdh?jhcgvufgc yud fddacdyi ty’d:sjhgfadgfad’sdgasudg fihdaf hadifcdyugadgf fuid’MTR


I need it to go


‘header:text fgaujfg asdfgasdgf iasdgffguiehf ifg izbgzsbv izs: fgayudg fadugf u’dfasdDFAHFIKAWE’DFGAD:OASFUI DFJASDGFUSD’dugfadjfgasdgf:djkagfjdksgf igfujd RECORD NUMBER:iyudfguadfgc uadfadufgvyuedgf’daifgadg fdjhfguasd fuabgfuabgfadb f’dhfuidgsafgdafgy dui gfuaygfa iydfg difgiagfia dohauihasfghau ::duigfg+dygfjhasdgfjhyadg dagfujadgfsdh?jhcgvufgc yud fddacdyi tyd:sjhgfadgfad’sdgasudg fihdaf hadifcdyugadgf fuidtext fgaujfg asdfgasdgf iasdgffguiehf ifg izbgzsbv izs: fgayudg fadugf u’dfasdDFAHFIKAWE’DFGAD:OASFUI DFJASDGFUSD’dugfadjfgasdgf:djkagfjdksgf igfujd RECORD NUMBER:iyudfguadfgc uadfadufgvyuedgf’daifgadg fdjhfguasd f’’uabgfuabgfadb f’dhfuidgsafgdafgy dui gfuaygfa iydfg difgiagfia dohauihasfghau ::duigfg+dygfjhasdgfjhyadg dagfujadgfsdh?jhcgvufgc yud fddacdyi tyd:sjhgfadgfad’sdgasudg fihdaf hadifcdyugadgf fuidtext fgaujfg asdfgasdgf iasdgffguiehf ifg izbgzsbv izs: fgayudg fadugf u’dfasdDFAHFIKAWE’DFGAD:OASFUI DFJASDGFUSD’dugfadjfgasdgf:djkagfjdksgf igfujd RECORD NUMBER:iyudfguadfgc uadfadufgvyuedgf’daifgadg fdjhfguasd fuabgfuabgfadb f’dhfuidgsafgdafgy dui gfuaygfa iydfg difgiagfia dohauihasfghau ::duigfg+dygfjhasdgfjhyadg dagfujadgfsdh?jhcgvufgc yud fddacdyi tyd:sjhgfadgfad’sdgasudg fihdaf hadifcdyugadgf fuid’MTR

‘header:text fgaujfg asdfgasdgf iasdgffguiehf ifg izbgzsbv izs: fgayudg fadugf u’dfasdDFAHFIKAWE’DFGAD:OASFUI DFJASDGFUSD’dugfadjfgasdgf:djkagfjdksgf igfujd RECORD NUMBER:iyudfguadfgc uadfadufgvyuedgf’daifgadg fdjhfguasd fuabgfuabgfadb f’dhfuidgsafgdafgy dui gfuaygfa iydfg difgiagfia dohauihasfghau ::duigfg+dygfjhasdgfjhyadg dagfujadgfsdh?jhcgvufgc yud fddacdyi tyd:sjhgfad’gfad’sdgasudg fihdaf hadifcdyugadgf fuidtext fgaujfg asdfgasdgf iasdgffguiehf ifg izbgzsbv izs: fgayudg fadugf u’dfasdDFAHFIKAWE’DFGAD:OASFUI DFJASDGFUSD’dugfadjfgasdgf:djkagfjdksgf igfujd RECORD NUMBER:iyudfguadfgc uadfadufgvyuedgf’daifgadg fdjhfguasd fuabgfuabgfadb f’dhfuidgsafgdafgy dui gfuaygfa iydfg difgiagfia dohauihasfghau ‘::duigfg+dygfjhasdgfjhyadg dagfujadgfsdh?jhcgvufgc yud fddacdyi tyd:sjhgfadgfad’sdgasudg fihdaf hadifcdyugadgf fuidtext fga’’ujfg asdfgasdgf iasdgffguiehf ifg izbgzsbv izs: fgayudg fadugf u’dfasd’DFAHFIKAWE’DFGAD:OASFUI DFJASDGFUSD’dugfadjfgasdgf:djkagfjdksgf igfujd RECORD NUMBER:iyudfguadfgc uadfadufgvyuedgf’daifgadg fdjhfguasd fuabgfuabgfadb f’dhfuidgsafgdafgy dui gfuaygfa iydfg difgiagfia dohauihasfghau ::duigfg+dygfjhasdgfjhyadg dagfujadgfsdh?jhcgvufgc yud fddacdyi tyd:sjhgfadgfad’sdgasudg fihdaf hadifcdyugadgf fuid’MTR


‘header:text fgaujfg asdfg’asdgf iasdgffguiehf ifg izbgzsbv izs: fgayudg fadugf u’dfasdDFAHFIKAWE’DFGAD:OASFUI DFJASDGFUSD’dugfadjfgasdgf:djkagfjdksgf igfujd RECORD NUMBER:iyudfguadfgc uadfadufgvyuedgf’daifgadg fdjhfguasd fuabgfuabgfadb f’dhfuidgsafgdafgy dui gfuaygfa iydfg difgiagfia dohauihasfghau ::duigfg+dygfjhasdgfjhyadg dagfujadgfsdh?jhcgvufgc yud fddacdyi tyd:sjhgfadgfad’sdgasudg fihdaf hadifcdyugadgf fuidtext fgaujfg asdfgasdgf iasdgffguiehf ifg izbgzsbv izs: fgayudg fadugf u’d’fasdDFAHFIKAWE’DFGAD’:OASFUI DFJASDGFUSD’dugfadjfgasdgf:djkagfjdksgf igfujd RECORD NUMBER:iyudfguadfgc uadfadufgvyuedgf’daifgadg fdjhfguasd fuabgfuabgfadb f’dhfuidgsafgdafgy dui gfuaygfa iydfg difgiagfia dohauihasfghau ::duigfg+dygfjhasdgfjhyadg dagfujadgfsdh?jhcgvufgc yud fddacdyi tyd:sjhgfadgfad’sdgasudg fihdaf hadifcdyugadgf fuidtext fgaujfg asdfgasdgf iasdgffguiehf ifg izbgzsbv izs: fgayudg fadugf u’dfasdDFAHFIKAWE’DFGAD:OASFUI DFJASDGFUSD’dugfadjfgasdgf:djkagfjdksgf igfujd RECORD NUMBER:iyudfguadfgc uadfadufgvyuedgf’daifgadg fdjhfguasd fuabgfuabgfadb f’dhfuidgsafgdafgy dui gfuaygfa iydf’g difgiagfia dohauihasfghau ::duigfg+dygfjhasdgfjhyadg dagfujadgfsdh?jhcgvufgc yud fddacdyi tyd:sjhgfadgfad’sdgasudg fihdaf hadifcdyugadgf fuid’MTR


‘header:text fgaujfg asdfgasdgf iasdgffguiehf ifg izbgzsbv izs: fgayudg fadugf u’dfasdDFAHFIKAWE’DFGAD:OASFUI DFJASDGFUSD’dugfadjfgasdgf:djkagfjdksgf igfujd RECORD NUMBER:iyudfguadfgc uadfadufgvyuedgf’daifgadg fdjhfguasd fuabgfuabgfadb f’dhfuidgsafgdafgy dui gfuaygfa iydfg difgiagfia dohauihasfghau ::duigfg+dygfjhasdgfjhyadg dagfujadgfsdh?jhcgvufgc yud fddacdyi tyd:sjhgfadgfad’sdgasudg fihdaf hadifcdyugadgf fuidtext fgaujfg asdfgasdgf iasdgffguiehf ifg izbgzsbv izs: fgayudg fadugf u’dfasdDFAHFIKAWE’DFGAD:OASFUI DFJASDGFUSD’dugfadjfgasdgf:djkagfjdksgf igfujd RECORD NUMBER:iyudfguadfgc uadfadufgvyuedgf’daifgadg fdjhfguasd fuabgfuabgfadb f’dhfuidgsafgdafgy dui gfuaygfa iydfg difgiagfia dohauihasfghau ::duigfg+dygfjhasdgfjhyadg dagfujadgfsdh?jhcgvufgc yud fddacdyi tyd:sjhgfadgfad’sdgasudg fihdaf ‘hadifcdyugadgf fuidtext fgaujfg asdfgasdgf iasdgffguiehf ifg izbgzsbv izs: fgayudg fadugf u’dfasdDFAHFIKAWE’DFGAD:OASFUI DFJASDGFUSD’dugfadjfgasdgf:djkagfjdksgf igfujd RECORD NUMBER:iyudfguadfgc uadfadufgvyuedgf’daifgadg fdjhfguasd fuabgfuabgfadb f’dhfuidgsafgdafgy dui gfuaygfa iydfg difgiagfia dohauihasfghau ::duigfg+dygfjhasdgfjhyadg dagfujadgfsdh?jhcgvufgc yud fddacdyi tyd:sjhgfadgfad’sdgasudg fihdaf hadifcdyugadgf fuid’MTR


‘header:text fgaujfg asdfgasdgf iasdgffguiehf ifg izbgzsbv izs: fgayudg fadugf u’dfasdDFAHFIKAWE’DFGAD:’ DFJASDGFUSD’dugfadjfgasdgf:djkagfjdksgf igfujd RECORD NUMBER:iyudfguadfgc uadfadufgvy’uedgf’daifgadg fdjhfguasd fuabgfuabgfadb f’dhfuidgsafgdafgy dui gfuaygfa iydfg difgiagfia dohauihasfghau ::duigfg+dygfjhasdgfjhyadg dagfujadgfsdh?jhcgvufgc yud fddacdyi tyd:sjhgfadgfad’sdgasudg fihdaf hadifcdyugadgf fuidtext fgaujfg asdfgasdgf iasdgffguiehf ifg izbgzsbv izs: fgayudg fadugf u’dfasdDFAHFIKAWE’DFGAD:OASFUI DFJASDGFUSD’dugfadjfgasdgf:djkagfjdksgf igfujd RECORD NUMBER:iyudfguadfgc uadfadufgvyuedgf’daifgadg fdjhfguasd fuabgfuabgfadb f’dhfuidgsafgdafgy dui gfuaygfa iydfg difgiagfia dohauihasfghau ::duigfg+dygfjhasdgfjhyadg dagfujadgfsdh?jhcgvufgc yud fddacdyi tyd:sjhgfadgfad’sdgasudg fihdaf hadifcdyugadgf fuidtext fgaujfg asdfgasdgf iasdgffguiehf ifg izbgzsbv izs: fgayudg fadugf u’dfasdDFAHFIKAWE’DFGAD:OASFUI DFJASDGFUSD’dugfadjfgasdgf:djkagfjdksgf igfujd RECORD NUMBER:iyudfguad’fgc uadfadufgvyuedgf’daifgadg fdjhfguasd fuabgfuabgfadb f’dhfuidgsafgdafgy dui gfuaygfa iydfg difgiagfia dohauihasfghau ::duigfg+dygfjhasdgfjhyadg dagfujadgfsdh?jhcgvufgc yud fddacdyi tyd:sjhgfadgfad’sdgasudg fihdaf hadifcdyugadgf fuid’MTR


‘header:text fgaujfg asdfgasdgf iasdgffguiehf ifg izbgzsbv izs: fgayudg fadugf u’dfasdDFAHFIKAWE’DFGAD:OASFUI DFJASDGFUSD’dugfadjfgasdgf:djkagfjdksgf igfujd RECORD NUMBER:iyudfguadfgc uadfadufgvyuedgf’daifgadg fdjhfguasd fuabgfuabgfadb f’dhfuidgsafgdafgy dui gfuaygfa iydfg difgiagfia dohauihasfghau ::duigfg+dygfjhasdgfjhyadg dagfujadgfsdh?jhcgvufgc yud fddacdyi tyd:sjhgfadgf’ad’sdgasudg fihdaf hadifcdyugadgf fuidtext fgaujfg asdfgasdgf iasdgffguiehf ifg izbgzsbv izs: fgayudg fadugf u’dfasdDFAHFIKAWE’DFGAD:OASFUI DFJASDGFUSD’dugfadjfgasdgf:djkagfjdksgf igfujd RECORD NUMBER:iyudfguadfgc uadfadufgvyuedgf’daifgadg fdjhfguasd fuabgfuabgfadb f’dhfuidgsafgdafgy dui gfuaygfa iydfg difgiagfia dohauihasfghau ::duigfg+dyg’fjhasdgfjhyadg dagfujadgfsdh?jhcgvufgc yud fddacdyi tyd:sjhgfadgfad’sdgasudg fihdaf ha’difcdyugadgf fuidtext fgaujfg asdfgasdgf iasdgffguiehf ifg izbgzsbv izs: fgayudg fadugf u’dfasdDFAHFIKAWE’DFGAD:OASFUI DFJASDGFUSD’dugfadjfgasdgf:djkagfjdksgf igfujd RECORD NUMBER:iyudfguadfgc ‘uadfad’ufgvyuedgf’daifgadg fdjhfguasd fuabgfuabgfadb f’dhfuidgsafgdafgy dui gfuaygfa iydfg ‘difgiagfia dohauihasfghau ::duigfg+dygfjhasdgfjhyadg dagfujadgfsdh?jhcgvufgc yud fddacdyi ty’d:sjhgfadgfad’sdgasudg fihdaf hadifcdyugadgf fuid’MTR



Report •

#19
July 7, 2010 at 11:13:12

Hey daragh_c,
I understand that you need the individual records separated. With
the "file" records broken down into rows in the master.txt,
wouldn't it now be possible to start using some of the more
traditional methods of parsing? In other words, instead of trying
to tackle one giant record without breaks, you now have at least
a little more manageable records to deal with, and may not be
constrained to some of the limitations you found earlier (line
length with FINDSTR, number of tokens with FOR, etc...)

Insomniac at large


Report •

#20
July 7, 2010 at 11:30:39

there are serveral occurances of the word HEADER in the below dump.
I'm more focused on this 'MTR'

Report •

#21
July 7, 2010 at 11:55:54

orange boy. The file1.txt is HUGE, there are over 200 records each with a header and an MTR per file !! A new file is created everyday and must be added to the previous file. The findstr works perfect once I have the file seperated (as above the way I want it).I simulated this by opening the master.txt in word using find and replace to make the space.I just need an automated way of doing this find and replace.Also the actuall files are well above the token and dilim lenght.The findstr will word, but will return the entire file because of the lack of line breaks :(

Razor, I had a look at the MTR as well and tryed adding a line break after every occurance, but figured it was the same code.Also in the actual file there are about 80 " ' "s in it so it runs out of tokens.Also the mtr is never after x amount of charaters, but it is the last thing on each record.


Report •

#22
July 7, 2010 at 12:18:17

Is it MTR, or 'MTR'? These things are important.

EDIT: You know what? This has been dragging on too long as is. You can probably figure out how to fix the search string yourself. Just save this as a VBS file, then drag your text file over the VBS file:

Option Explicit
Const magicStr = "'MTR'"

If WScript.Arguments.Count = 0 Then
  MsgBox "No Arguments; aborting", vbCritical, WScript.ScriptName
  WScript.Quit 1
End If
Dim fso, fIn, fOut, buff, carryover, arg, strLen
Set fso = CreateObject("Scripting.FileSystemObject")
strLen = Len(magicStr) - 1

For Each arg In WScript.Arguments
  carryover = Space(strLen)
  Set fIn  = fso.OpenTextFile(arg)
  Set fOut = fso.OpenTextFile(fso.GetBaseName(arg) & ".out." _
    & fso.GetExtensionName(arg), 2, True)

  Do Until fIn.AtEndOfStream
    buff = fIn.Read(4096)
    buff = Replace(carryover & buff, magicStr, magicStr & vbNewLine)
    fOut.Write Mid(buff, strLen + 1)
    carryover = Right(buff, strLen)
  Loop
Next 'arg
MsgBox "Done", vbOKOnly, WScript.ScriptName


Report •

#23
July 7, 2010 at 13:00:56

Thats amazing, it really is, but, like a twat that I am, i left out a thing I forgot to add in. the MTR is actuall 'mtr= XX' where XX' is a number. This number is vital. My bad I know.

Can i just change the Const magicStr = "'MTR'" to Const magicStr = "'MTR'"+??" ' " or the next two digits. I think the MTR= will only ever be a double didgit figure. Really sorry and that VB script works cool. I remember now why I was hoping to get the line break before the "HEADER" as it would have avoided this.

I also ran it from the cmd by typing "code.vbs text.txt" and it exported a new file - which is super amazing !!!!

I don't suspose there is any way I can help you with anything ?

Really top marks.


Report •

#24
July 7, 2010 at 13:25:28

See? THIS is why I asked for 10 live records. It prevents these kinds of problems.

Does each record start with ‘header:? And is that it, exactly? Including capitalization?


Report •

#25
July 7, 2010 at 13:55:59

fair point Razor,fair point. It wil be always 'header=X' where X is a number,but it could be 'header=XXX. However, if one one these records needs to be reloaded we will always manually change this to 1 so in short the XXX dose not need to be presereverd.

Also I note that the first instance of the MTR did not put a line break, but it's ok, one record is fine.I don't think im holding anything else back... for now :)


Report •

#26
July 7, 2010 at 13:58:55
✔ Best Answer

Option Explicit
Const magicStr = "'header="

If WScript.Arguments.Count = 0 Then
  MsgBox "No Arguments; aborting", vbCritical, WScript.ScriptName
  WScript.Quit 1
End If
Dim fso, fIn, fOut, buff, peek, arg, strLen
Set fso = CreateObject("Scripting.FileSystemObject")
strLen = Len(magicStr) - 1

For Each arg In WScript.Arguments
  peek = ""
  Set fIn  = fso.OpenTextFile(arg)
  Set fOut = fso.OpenTextFile(fso.GetBaseName(arg) & ".out." _
    & fso.GetExtensionName(arg), 2, True)

  Do Until fIn.AtEndOfStream
    buff = peek & fIn.Read(4096)
    If Not fIn.AtEndOfStream Then
      peek = fIn.Read(strLen)
    Else
      peek = ""
    End If
    buff = Replace(buff & peek, magicStr, vbNewLine & magicStr)
    fOut.Write Left(buff, Len(buff) - Len(peek))
  Loop
  fOut.Write peek
Next 'arg
MsgBox "Done", vbOKOnly, WScript.ScriptName


Report •

#27
July 7, 2010 at 14:05:36

hey Man,

Im getting a few pop up box's

1st one says Loop: "gasudg"
then Loop : ""

then it says done

Any ideas ?


Report •

#28
July 7, 2010 at 14:07:30

I have no idea what you're talking about. I certainly didn't accidentally post the debug version, then go back and edit in the real version. You must be crazy.

Report •

#29
July 8, 2010 at 01:30:38

heh heh heh

Report •

#30
July 8, 2010 at 01:45:08

Ps it works perfect now, thanks a mill, really good

Report •

#31
July 8, 2010 at 07:25:54

Just one last question, and yes I know I've used considerable resources.., Basicly All I want now is when I type the record number the findstr is returning the entire record (Which is perfect). However, is there any way that when I find the record number the batch script will then search back up wards for a line of text which could be X amount of lines above. For instance the layout is like this

ENV XX IMPORTAND LINE
Header - MTR
Header - MTR
Header - MTR
Header - MTR
ENV XX IMPORTAND LINE
Header - MTR
Header - MTR -- >> I want this record and then search up and return the closest instance of "ENV XX IMPORTAND LINE
Header - MTR
Header - MTR
Header - MTR

My final result will be :

ENV XX IMPORTAND LINE
header - MTR

I have the header - Mtr, it's just pulling in the "ENV XX IMPORTAND LINE" into the top of the record thats the problem. And thats it !.


here is the batch im using

echo "Enter search critera"
set /p polNumber=

findstr /S %polNumber% masterFormated.txt > searchResults.txt

if %errorlevel%==0 (

echo Found results for : %polNumber%
echo.
echo see "SearchResult.txt"
echo.
echo PRESS ANY KEY TO EXIT
set /p exit1=


) else (
echo could not find results for : %polNumber%
echo PRESS ANY KEY TO EXIT
set /p exit2=

)

The masterFormated.txt file is the one created from your vbs script. Not sure if this helps, any sugestion would be great.I can send u over a few records if u pm me ur e-mail, as is private stuff


Report •

#32
July 9, 2010 at 04:31:40

It's been done, yes.But I don't think the people who would provide code are going to get that far in this thread (too much VBScript, too much, well, me). Your best bet would be to start a new thread.

Report •

#33
July 19, 2010 at 14:17:36

hello
An easy way
Bring your file to easy path.
Go to command [dos] mode.
Change directories and locate file.
Use "edit" command.
EDIT xxx.txt
In 'edit' , use 'search' . Use 'replace'.
In 'find', put characters that you have at end of each line.
In replace give <ctrl+p><ctrl+j><ctrl+p><ctrl+m> .
[this is ^p to input special character then ^j for line feed ,same ^p^m for carriage return]
It will ask and do replacements. Some funny character will show. Try ; Then do it replace-all.
Note- DOS can handle only upto 64k size.So may need splitting................it works, all the best , pl revert to me at ablewasi12@gmail.com , if query / success
edit help at http://www.computerhope.com/edithlp...

Report •


Ask Question