Carriage Return with tilde from multiple rows to one row

Hello Experts:

I have a text file that I need to:

1) DELETE all asterisks at the end of each row if any.

2) COMBINE all rows with tilde

See attached excel file and Original and New .txt files.


I have a vbs script file that will convert from one row with tilde to different rows. See attache vbs file.

Please help.

Thank you again for all your help.
Delete1st_and_Combine2ndwithTilde.xlsx
Original_320048803_15172018.txt
New_320048803_15172018.txt
ReformatUnixText.vbs
Queennie LAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

oBdACommented:
Drop VBScript. "It's not pinin'! It's passed on! This language is no more! It has ceased to be! It's expired and gone to meet its maker! It's a stiff! Bereft of life, it rests in peace! If you hadn't nailed it to the perch it'd be pushing up the daisies! Its metabolic processes are now 'istory! It's off the twig! It's kicked the bucket, it's shuffled off its mortal coil, run down the curtain and joined the bleedin' choir invisibile!! THIS IS AN EX-LANGUAGE!!" (Monty Python, obviously).
This is an easy one-liner in PowerShell:
(Get-Content -Path C:\temp\in.txt | % {$_.TrimEnd('*')}) -join '~' | Set-Content -Path C:\temp\out.txt 

Open in new window

0
Queennie LAuthor Commented:
@oBdA:

I never used PowerShell before. Can you please redirect me how to use it? Thank you.
0
Queennie LAuthor Commented:
@oBdA:

There multiple text files also.

Thanks.
0
Fundamentals of JavaScript

Learn the fundamentals of the popular programming language JavaScript so that you can explore the realm of web development.

oBdACommented:
And these "multiple text files" would be identifiable how?
0
Queennie LAuthor Commented:
@oBdA:

From SQL table output this to multiple text files dynamically named it as filename_today'sdate.txt using SSIS with a unique filename for each row in text file. That is working but the problem is it creates a bunch of asterisks at the end of each row in each text files.

I don't know how to delete them and create to do the one line as for each as tilde.

Thanks.
0
Queennie LAuthor Commented:
@oBdA:

The multiple text files output from 1 SQL table with a column named "Filename" dynamically named after the filename+today'sdate.txt using SSIS. This creation of multiple text files is working. The only problem I have:

1) is the asterisks at the end of each row if any. DELETE all asterisks at the end of each row if any.
2) combine all rows after deletion into one row and insert tilde after each row.

Thank you.
0
Queennie LAuthor Commented:
Any help?

Thanks.
0
Queennie LAuthor Commented:
I have VBScript but it deleted rows but not the asterisks.

Const ForReading = 1

Const ForWriting = 2

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objFile = objFSO.OpenTextFile("C:\New.txt", ForReading)


Do Until objFile.AtEndOfStream

    strLine = objFile.ReadLine

    If InStr(strLine, "********") = 0 Then

        strNewContents = strNewContents & strLine & vbCrLf

    End If

Loop


objFile.Close


Set objFile = objFSO.OpenTextFile("C:\New.txt", ForWriting)

objFile.Write strNewContents


objFile.Close

Open in new window

0
Bill PrewCommented:
Here is a small VBS that does the changes to a single file.  Run as follows

cscript EE29100161.vbs Original_320048803_15172018.txt

or

cscript EE29100161.vbs Original_320048803_15172018.txt New_320048803_1517201
8.txt


In the first case the input file will be overwritten with the changes.  In the second case the input file will be read, and the changes written to the second file.

' Define needed constants
Const ForReading = 1
Const ForWriting = 2
Const TriStateUseDefault = -2
 
' Get input file name from command line parm
If (WScript.Arguments.Count > 0) Then
   strInFile = WScript.Arguments(0)
Else
   WScript.Echo "No input filename specified."
   WScript.Quit
End If

' Get output file name from command line parm
If (WScript.Arguments.Count > 1) Then
   strOutFile = WScript.Arguments(1)
Else
   strOutFile = strInFile
End If

' Create filesystem object
Set objFSO = CreateObject("Scripting.FileSystemObject")

' Make sure input file exists
If Not objFSO.FileExists(strInFile) Then
   Wscript.Echo "ERROR: Input file """ & strInFile & """ does not exist."
   Wscript.Quit
End If

' Read file into an array
With objFSO.OpenTextFile(strInFile, ForReading, False, TriStateUseDefault)
    strData = .ReadAll
    .Close
End With

' Make desired changes
Do While Instr(strData, "*" & vbCrLf) > 0
  strData = Replace(strData, "*" & vbCrLf, vbCrLf)
Loop
strData = Replace(strData, vbCrLf, "~")

' Write output file
With objFSO.OpenTextFile(strOutFile, ForWriting, True)
    .Write strData
    .Close
End With

Open in new window


»bp
0
Bill PrewCommented:
If you want to process all files in a folder, then we could either drive my last post by a BAT file calling it for each file, or add the logic to the VBS file.  Any preference?

Should all files in the folder that match a particular pattern be processed, and what should that pattern be?


»bp
0
Queennie LAuthor Commented:
@Bill Prew:

I have multiple files and I tried to incorporate the last post you had with file directory but I have and error "No input filename specified"

Here's the vbscript:

' Require variables to be defined before used
Option Explicit

' Specify file and folder locations
Const strBaseDir = "C:\TextFiles\"
Const strDestDir = "C:\TextFilesOutput\"




' Define needed constants
Const ForReading = 1
Const ForWriting = 2
Const TriStateUseDefault = -2
 
' Get input file name from command line parm
If (WScript.Arguments.Count > 0) Then
   strInFile = WScript.Arguments(0)
Else
   WScript.Echo "No input filename specified."
   WScript.Quit
'End If

' Get output file name from command line parm
If (WScript.Arguments.Count > 1) Then
   strOutFile = WScript.Arguments(1)
Else
   strOutFile = strInFile
End If

' Create filesystem object
Set objFSO = CreateObject("Scripting.FileSystemObject")


' Quit if folders don't exist
If Not objFSO.FolderExists(strBaseDir) Then
   Wscript.Echo Now & " ERROR: Base folder """ & strBaseDir & """ does not exist, quiting."
   Wscript.Quit
End If
If Not objFSO.FolderExists(strDestDir) Then
   Wscript.Echo Now & " ERROR: Destination folder """ & strDestDir & """ does not exist, quiting."
   Wscript.Quit
End If

' Make sure input file exists
If Not objFSO.FileExists(strInFile) Then
   Wscript.Echo "ERROR: Input file """ & strInFile & """ does not exist."
   Wscript.Quit
End If

' Read file into an array
With objFSO.OpenTextFile(strInFile, ForReading, False, TriStateUseDefault)
    strData = .ReadAll
    .Close
End With

' Make desired changes
Do While Instr(strData, "*" & vbCrLf) > 0
  strData = Replace(strData, "*" & vbCrLf, vbCrLf)
Loop
strData = Replace(strData, vbCrLf, "~")

' Write output file
With objFSO.OpenTextFile(strOutFile, ForWriting, True)
    .Write strData
    .Close
End With

Open in new window


Thank you.
0
Bill PrewCommented:
This should work.

' Require variables to be defined before used
Option Explicit

' Specify file and folder locations
Const strBaseDir = "C:\TextFiles\"
Const strDestDir = "C:\TextFilesOutput\"

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

' Define global variables
Dim objFSO, strData, objBaseDir, objFile

' Create filesystem object
Set objFSO = CreateObject("Scripting.FileSystemObject")

' Quit if folders don't exist
If Not objFSO.FolderExists(strBaseDir) Then
    Wscript.Echo Now & " ERROR: Base folder """ & strBaseDir & """ does not exist, quiting."
    Wscript.Quit
End If
If Not objFSO.FolderExists(strDestDir) Then
    Wscript.Echo Now & " ERROR: Destination folder """ & strDestDir & """ does not exist, quiting."
    Wscript.Quit
End If

' Access base folder
Set objBaseDir = objFSO.GetFolder(strBaseDir)

' Process every file in the base folder
For Each objFile In objBaseDir.Files

    ' Read file into an array
    With objFSO.OpenTextFile(objFile.Path, ForReading, False, TriStateUseDefault)
      strData = .ReadAll
      .Close
    End With

    ' Make desired changes
    Do While Instr(strData, "*" & vbCrLf) > 0
    strData = Replace(strData, "*" & vbCrLf, vbCrLf)
    Loop
    strData = Replace(strData, vbCrLf, "~")

    ' Write output file
    With objFSO.OpenTextFile(strDestDir & objFile.Name, ForWriting, True)
      .Write strData
      .Close
    End With

Next

Open in new window


»bp
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Queennie LAuthor Commented:
@Bill Prew:

OMG! WOW! It is working.

Thank you very much.

I really appreciate it.
0
Bill PrewCommented:
Welcome.


»bp
0
Queennie LAuthor Commented:
Thank you again Bill for sharing your intelligence and expertise.

I really appreciate it.

Have a wonderful day Sir!
1
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.