Question

Replace New Page Character in multiple text files - want something I can schedule

Asked by: RR345

I have multiple text files created from a main frame that will format for an Access 2000 import during off hours. I am able to schedule formatting the files in Monarch and running imports into Access. The only problem is that the files, which are actually reports, from the main frame have page characters. This causes the headers in Monarch to fail as the characters are deleted along with the first one or two letters to the right of the characters. If I can remove the characters before formatting in Monarch, the problem is solved. I have tested this using find and replace in Notepad, but is not a global solution to the 100s of files I need to import. OS is XP.

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2008-05-15 at 08:42:47ID23405611
Topics

Windows Batch Scripting

,

Microsoft Access Database

Participating Experts
2
Points
250
Comments
18

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. COLD FUSION SCHEDULER
    I have this weird problem: I set up cold fusion scheduler to run tasks at the top of the hour (i.e. 9:00 AM) and at 3/4 past the hour (i.e. 9:45 AM) and it should run every hour on the hour. I set it up to start at a certain hour until 'indefinitely' and each one should ru...
  2. Scheduling Tasks
    I am trying to schedule Defrag, Disk cleanup, etc to run overnight in the Task Scheduler. Can't figure out how to do it. I though at first I was having trouble because I hadn't used a password when I installed Windows XP but I then added one and it still won't run.What is Idl...
  3. Scheduled Task
    Kindly teach me how to install only the Scheduled task for windows 2000 advance server. 1 of Our server does'nt have Scheduled task and they want it now, Tnks in advance....
  4. Defragmenter schedule
    How can I schedule the deframenter tool on windows xp? THX jdff

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: JesterTooPosted on 2008-05-15 at 09:26:46ID: 21575416

Look for a Windows port of the *nix utility SED.  It is extremely easy to use for this.  If you could post a fragment (large enough to include the "new page" character) I could give you an example.

The sample is necessary because "mainframe" doesn't necessarily signify exactly how the data might look in the actual file.

If the "new page" character is x'0C' (decimal 12) = @, then this should work...

   sed "s/\x0C//g  <oldfile >newfile

construct a bat file that can loop through each of your files and substitute their filenames into this command.

 

by: JesterTooPosted on 2008-05-15 at 09:30:17ID: 21575453

Note... the previous comment shows the @ symbol... the actual symbol is the symbol for "male"... a circle with a cross dangling straight down from it.  You can see that symbol in a command prompt if you hold down the ALT key and press the 1 key on the numeric keypad, release the 1, then press the 2, then release all keys.

 

by: RR345Posted on 2008-05-15 at 11:10:16ID: 21576548

I tried the following. Thought I could modify it to look for the character but may work only for text.

@echo off
   setlocal
   set SEARCHDIR=R:\LPIReporting\TempImportFiles
   set FILETYPE=*.txt
   set TRIGGER=TEST
   set OLDTEXT=?
   set NEWTEXT=
   ECHO "%OLDTEXT%" "%NEWTEXT% > Replace.ini
   FOR /F "usebackq" %%X IN (`findstr /S /I /M "%trigger%" "%SEARCHDIR%\%FILETYPE%"`)  DO Munge.exe R:\LPIReporting\TempImportFiles\Replace.ini %%X

Attached is a portion of the file. And yes, the symbol is as Jester states in command prompt window.

 

by: JesterTooPosted on 2008-05-15 at 16:09:40ID: 21578667

This bat file seems to work...

I'm using the SED from the CygWin package, but it's likely any version will work (there are some differences between various versions).

::@echo off
 
:: process each txt file in SourcePath directory
:: via SED to remove formfeed character writing
:: updated file to TargetPath directory.
::
:: NOTE:  Bypasses any files which already exist
::        in TargetPath
 
setlocal
 
set SourcePath=dir1
set TargetPath=dir2
 
for /f "tokens=* delims=" %%V in ('dir /a-d /b %SourcePath%\*.txt') do (
   if not exist %TargetPath%\%%V (
      sed "s/\x0C//g"  <%SourcePath%\%%V >%TargetPath%\%%V
   )
)
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:

Select allOpen in new window

 

by: JesterTooPosted on 2008-05-15 at 16:10:40ID: 21578673

sorry to spam you... forgot to add that the sample file you attached had no formfeed characters in it.

 

by: canaliPosted on 2008-05-16 at 02:17:31ID: 21581136

This is a pure batch to strip From Feed char

Bye Gastone

@echo off
::: process each txt file in SourcePath directory
:: pure batch to remove formfeed character writing
:: updated file to TargetPath directory.
:: by Gastone Canali
setlocal
set SourcePath=C:\Documents and Settings\g
set TargetPath=c:\temp
cd /D %targetPath%   || goto :ERR
cd /D "%SourcePath%" || goto :ERR1
 
for /f "tokens=* delims=" %%F in ('dir /a-d /b "%SourcePath%\x*.txt"') do set file=%%F&call :parseFile
      
endlocal 
goto :EOF 
     
:parseFile
        type nul >"%TargetPath%\%file%" 2>nul
        for /f " tokens=*" %%a in ('type "%file%"') do set value=%%a&call :parseLine 
goto :eof
:: strip the from feed
::  the fromfeed char is in  between : and =
:parseLine
         set newvalue=%value:=%
         echo %newvalue% >>"%TargetPath%\%file%"
goto :eof
:ERR
echo Target dir not found!
:ERR1
echo Source dir not found!
:end
:eof

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:

Select allOpen in new window

 

by: RR345Posted on 2008-05-16 at 07:31:53ID: 21583062

2nd solution is really, really close. I appreciate your work. As I am not proficient with batch files, I am having a little trouble gettig my exact solution from your proposal. I just want to remove every instance of while leaving the rest of the file intact. I have played with it, but cannot figure out how to isolate the character. Thanks so much.

 

by: JesterTooPosted on 2008-05-16 at 08:14:37ID: 21583454

RR345

Have you tried the script I provided?

Since it uses SED you can obtain it here:  http://www.physionet.org/physiotools/cygwin/

Install the CygWin utilities (there are many!), then either copy sed.exe to somewere in your path or add the CygWin\bin location to your path.  (I recommend the former just to be safe since I don't know what other executables you may already have on your machine and there could be a conflict between sam-named files).

Then, just run the script above and check the output.  As written, it never alters the original input files.

 

by: canaliPosted on 2008-05-16 at 08:17:19ID: 21583482

explain better what u want.
My script remove all FF...

 

by: RR345Posted on 2008-05-16 at 10:42:41ID: 21584840

These are really good suggestions. I am going on vacation for a week and will need to revisit when I return. Hang in there with me. Thanks

 

by: RR345Posted on 2008-05-27 at 07:50:00ID: 21652297

Jester, I downloaded the CygWin and copied everything accordingly including the script you kindly provided. What is happening now, is that I get entirely blank text files. I am reattaching one of the text files. Please look at the characters prior to the text AMSBC510. Looking forward to your respons.

 

by: JesterTooPosted on 2008-05-27 at 12:53:14ID: 21655077

The posted script worked perfectly for me.  It found/removed 3 occurrences of a FormFeed from the original file (size was 2658 bytes) and produced an output file without the 3 characters (size was 2655 bytes) but with all other data intact.

If you made any modifications to the script, please repost it so I can check it.

Thanks,
Lynn

 

by: RR345Posted on 2008-05-28 at 06:18:26ID: 21660076

Okay, here's the code--

::@echo off
:: process each txt file in SourcePath directory
:: via SED to remove formfeed character writing
:: updated file to TargetPath directory.
::
:: NOTE:  Bypasses any files which already exist in TargetPath
 
setlocal
set SourcePath=R:\LPIReporting\TempImportFiles
set TargetPath=R:\LPIReporting\TempImportFiles\Temp
 
for /f "tokens=* delims=" %%V in ('dir /a-d /b %SourcePath%\*.txt') do (
   if not exist %TargetPath%\%%V (
      sed "s/\x0C//g"  <%SourcePath%\%%V >%TargetPath%\%%V
   )
)

Maybe there is a problem with sed on my machine?

 

by: RR345Posted on 2008-05-28 at 08:15:25ID: 21661164

I got sed to run by placing all of the files in bin into the source path. So now I have data in my files. It is replacing other "hidden" characters that I do not want replaced as I want to keep the format. The attached files show what I mean SEDInput1 to SEDOutput1 is results using your code. Output2_ShouldBe are the results I want. Both Output files use the same Input file. Is this going to be possible. Thanks again.

 

by: JesterTooPosted on 2008-05-28 at 11:11:03ID: 21662763

The character being dropped is the "Carriage Return".  *nix uses only a Line Feed character to terminate lines while Windows/DOS uses a Carriage Return and Line Feed pair.

Are you using the version of SED from the Cygwin package?  It follows the WIndows convention while some other ports of SED follow the *nix convention.

>>> I got sed to run by placing all of the files in bin into the source path.  <<<

I'm not sure if that means you put all of Cygwin's bin folder files into your path or whether you are referring to just your data files.  The way my system is configured is that I have a "util" folder that is one of the earliest folders listed in my PATH environment variable.  Then, I only put the exe files I intend to use in the util folder.  Thus I only have SED, TEE, and a few other of the Cygwin files that are readily accessible along with some other utility programs from other sources.  I don't know if there might be some Cygwin file that is causing your copy to differ in behavior from my copy... I looked for a "configuration" file that might provide an option for line termination style preferences but did not find one.

 

by: RR345Posted on 2008-05-28 at 11:58:20ID: 21663215

I put the sed.exe in the file path but it kept looking for some .dlls in the bin file, so I copied everything to the file path. As far as I know, I am using SED from the Cygwin package - I used the link you provided. So when you run the same code, your file looks like Output1_ShouldBe.txt that I posted in my previous comment?

 

by: RR345Posted on 2008-05-29 at 07:01:17ID: 21669160

Here's the solution:
Add -b to provided code
 sed -b "s/\x0C//g"
--binary
This option is available on every platform, but is only effective where the operating system makes a distinction between text files and binary files. When such a distinction is madeas is the case for MS-DOS, Windows, Cygwintext files are composed of lines separated by a carriage return and a line feed character, and sed does not see the ending CR. When this option is specified, sed will open input files in binary mode, thus not requesting this special processing and considering lines to end at a line feed.

Thanks

 

by: RR345Posted on 2008-05-29 at 07:03:20ID: 31458332

Thanks for your help. I learned a great deal about SED and will probably use it for other things.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...