Solved

Multiline File to CSV

Posted on 2013-06-19
4
400 Views
Last Modified: 2013-07-23
Experts,

I have a large number of multiline files, that look like the below example.  Could these files be reformatted as a CSV automatically?  Could you do a replace in Powershell to remove the new line breaks and replace them with Commas?

BEGMF;
MFVERSION 2;
MFDESC;
 BeginImportJob
  AutoApproved = True
  Class = Document
  DeleteProcessedFiles = True
  RequireReview = False
 BeginObject
  FileName = \\server\temp$\Tiffs\823609E02.tif
   BeginAttributes
    Document_Number = 823609
    Document_Name = 823609E02.tif
    Document_Revision = L
    Document_Type = Tiff
    Document_Description = DOCUMENT DESCRIPTION
    SheetNum = 02
    ReleaseDate = 05/08/2009
    DrawnBy = FIUKSP    
   EndAttributes
  EndObject
  EndImportJob
  ENDMF;

Open in new window

0
Comment
Question by:lm1189
  • 2
4 Comments
 
LVL 40

Expert Comment

by:Subsun
Comment Utility
Can you give a sample output which you are expecting?
0
 

Author Comment

by:lm1189
Comment Utility
A CSV, with all the lines as columns. IE:

BEGMF;,MFVERSION 2;,MFDESC;, BeginImportJob,  AutoApproved = True,Class = Document  ,DeleteProcessedFiles = True

Open in new window

0
 
LVL 40

Accepted Solution

by:
Subsun earned 250 total points
Comment Utility
Try with following code and see if it works for you..
Set-Content C:\Temp\result.csv ((GC C:\temp\input.txt) -join ",")

Open in new window

Replace C:\temp\input.txt with input file path
C:\Temp\result.csv is the output file..
0
 
LVL 51

Assisted Solution

by:Bill Prew
Bill Prew earned 250 total points
Comment Utility
Here's a small VBS that should do the job.

Run as

cscript EE28161581.vbs EE28161581.in ee28161581.out

or

cscript EE28161581.vbs EE28161581.in

in the first case it reads from the first file and writes to the second.  In the second case it reads from the first file and over writes it with the changes.

' Define needed constants
Const ForReading = 1
Const ForWriting = 2
Const TriStateUseDefault = -2

' Get input file name from command line parm, if 2 parms entered
' use second as new output file, else rewrite to input file
If (WScript.Arguments.Count > 0) Then
   strInFile = WScript.Arguments(0)
Else
   WScript.Echo "No filename specified."
   WScript.Quit
End If
If (WScript.Arguments.Count > 1) Then
   strOutFile = WScript.Arguments(1)
Else
   strOutFile = strInFile
End If

' Read file into an array
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strInFile, ForReading, False, TriStateUseDefault)
strData = objFile.ReadAll
objFile.Close

strData = Replace(strData, vbCrLf, ",")
strData = Replace(strData, "ENDMF;,", "ENDMF;" & vbCrLf)

' Rewrite file with any changes made
Set objFile = objFSO.OpenTextFile(strOutFile, ForWriting, True)
objFile.Write strData
objFile.Close

Open in new window

~bp
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now