Text file cleaning

Hello

I have a text file with 800 entries and I am trying to find a solution to clean it a little bit.
The contents are split into "Records" ( record 1, 2 , 3 , etc ).
What I am trying to do is eliminate the empty records from the file.
I am attaching a sample of the file and some other explanation.
I can code in C# .NET , CMD ( BATCH FILE ) , visual basic script, etc

Thank you in advance

RECORD 00001
2000/01/01 00:17:32
PAR 1: 1 
PAR 6:     
PAR 2:   
PAR 7:     
PAR 3:   
PAR 8:     
PAR 4:   
PAR 9:     
PAR 5:   
PAR 10:      
-----------------------
RECORD 00002
2000/01/01 00:17:32
PAR 1: 1 
PAR 6:     
PAR 2: 34242342342  
PAR 7:     
PAR 3:   
PAR 8: 55535328883    
PAR 4:   
PAR 9:     
PAR 5:   
PAR 10:      
-----------------------
RECORD 00003
2000/01/01 00:17:32
PAR 1:  
PAR 6:    
PAR 2:   
PAR 7:      
PAR 3:   
PAR 8:      
PAR 4:   
PAR 9:     
PAR 5:   
PAR 10:     
-----------------------



/// In this file, i need to eliminate both Record 00001 and 00003, because they contain invalid information.
/// I have calculated the total number of characters that constitute an empty record : 98
/// I want to set a rule in the script, to delete the record if it has less then 100 characters...
/// For example Record 00001 has 99 characters, therefore will be deleted.
/// Thank you

Open in new window

giberiskAsked:
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.

wdosanjosCommented:
Please try the following:

var istream = new StreamReader(new FileStream(@"c:\temp\infile.txt", FileMode.Open));
var ostream = new StreamWriter(new FileStream(@"c:\temp\outfile.txt", FileMode.Create));
StringBuilder sb = new StringBuilder();
int size = 0;

for (string line = istream.ReadLine(); line != null; line = istream.ReadLine())
{
	line = line.Trim();

	sb.Append(line).Append("\r\n");
	
	if (line != "-----------------------")
	{
		size += line.Length;
	}
	else
	{	// end of record
		if (size >= 100)
		{
			ostream.Write(sb.ToString());
		}

		sb.Length = 0;
		size = 0;
	}
}

istream.Close();
ostream.Close();

Open in new window

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
giberiskAuthor Commented:
What language is this please ?
0
giberiskAuthor Commented:
Nevermind I got it working...
Thank you so much
if you care for my other question I will be very greatfull !
Thanks again

http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_26936272.html
0
giberiskAuthor Commented:
Super
0
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
Windows Batch

From novice to tech pro — start learning today.