Computing.Net > Forums > Programming > batch to delete lines in text

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

batch to delete lines in text

Reply to Message Icon

Name: jshazxd
Date: May 13, 2009 at 00:19:36 Pacific
OS: Windows XP
Subcategory: Batch
Comment:

Hi, i want to write a batch to do the following job. Now i have a.txt and b.txt. a.txt contains the information like:
List1 Error SimulationError a
List2 Error SimulationError b
List3 Error SimulationError c
List4 Error SimulationError d
and b.txt contains information like:
List1
List4 Error SimulationError d
The batch will scan a.txt and b.txt, and then delete those lines which contains certain line from b.txt and.
anyone can give a help? thanks



Sponsored Link
Ads by Google

Response Number 1
Name: jshazxd
Date: May 13, 2009 at 00:21:23 Pacific
Reply:

add: the output file will contain the following:
List2 Error SimulationError b
List3 Error SimulationError c


0

Response Number 2
Name: jshazxd
Date: May 13, 2009 at 01:19:52 Pacific
Reply:

it's also fine to use vbs .i know how to do it in vb, can anyone help me to convert it to vbs.
Imports System
Imports System.IO
Module Module1

Sub Main(ByVal args() As String)
Try
Dim f As New FileInfo(args(0).ToString)
Dim s As String() = File.ReadAllLines(f.FullName, System.Text.Encoding.Unicode)

Dim e As New FileInfo(args(1).ToString)
Dim t As String() = File.ReadAllLines(e.FullName, System.Text.Encoding.Unicode)
'MsgBox(t.Length)

Dim linenumber As Integer = 0
Dim warnings As New ArrayList
Dim errors As New ArrayList

Dim content As String
Dim contentExc As String
Dim i As Integer = 0
Dim j As Integer = 0
Dim counter As Integer = 0
While i < s.Length
content = s(i)
j = 0
'MsgBox(content)
While j < t.Length
contentExc = t(j)
'MsgBox(contentExc)
If content.Trim.Contains(contentExc.Trim) Then
GoTo Ignore
End If
j += 1
End While


If content.Contains("WARNING") Then warnings.Add(content)
If content.Contains("ERROR") Then errors.Add(content)
Ignore:
i += 1
End While

Using out As New StreamWriter(f.FullName & "_full", True)

'out.WriteLine(ExceptionFile(0))


i = UBound(args)
If i <> 0 Then
out.WriteLine("The file contains the excepted can be found at \\inventor\Main\Setups\Install\Tools\MSIVAL2")
End If


out.WriteLine("")
out.WriteLine("ERRORS: " & errors.Count)
out.WriteLine("WARNINGS: " & warnings.Count)

If errors.Count = 0 Then
GoTo NoError 'since no error is detected, no need to display "first 10 errors"
End If
out.WriteLine("")
out.WriteLine("First 10 errors:")
out.WriteLine("")

j = 0
Dim err As String
For Each err In errors
j += 1
out.WriteLine(err)
If j > 9 Then Exit For
Next
NoError:
out.WriteLine("")
out.WriteLine("")
out.WriteLine("")
out.WriteLine("")

End Using

Catch ex As Exception
Console.WriteLine("Exception caught in FormatMail - " & ex.Message & " - You must provide a full path file name")
End Try
End Sub

End Module


0

Response Number 3
Name: ghostdog
Date: May 13, 2009 at 02:41:14 Pacific
Reply:

if you can afford to use other languages, such as Python, here's an alternative solution

data1=open("file1").read().split("\n")
data2=open("file2").read().split("\n")
print set(data1).difference(data2)


0
Reply to Message Icon

Related Posts

See More


@ECHO OFF won't suppress ... read from file to check f...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: batch to delete lines in text

Batch file to delete folder in fol. www.computing.net/answers/programming/batch-file-to-delete-folder-in-fol/16994.html

Batch file to delete lines in large CSV file www.computing.net/answers/programming/batch-file-to-delete-lines-in-large-csv-file/20291.html

Batch to Delete files in a folder www.computing.net/answers/programming/batch-to-delete-files-in-a-folder/16299.html