473,394 Members | 1,971 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Count and delete in file

4
Hi,
So i have this program which read single text file and write in other. Basically read every line then write to another file "this number is n times here + numbers".

Can someone help me to modify this to store only 1 time the number in second file. What I mean is not like now:

Now output is:
Expand|Select|Wrap|Line Numbers
  1. Count of matching numbers in this group: 7
  2. Numbers:
  3. 01070400
  4. 01070400
  5. 01070400
  6. 01070400
  7. 01070400
  8. 01070400
  9. 01070400
Is better to be:
Expand|Select|Wrap|Line Numbers
  1. Count of matching numbers in this group: 7
  2. Number:
  3. 01070400
  4.  
Code that I use is:
Expand|Select|Wrap|Line Numbers
  1.             string path = "text.txt";
  2.  
  3.             var result = (File.ReadLines(path)).OrderBy(x => x).GroupBy(x => x);
  4.  
  5.             using (var writer = new StreamWriter("test1.txt"))
  6.             {
  7.                 foreach (var item in result)
  8.                 {
  9.                     string outGrp = String.Format("Count of matching numbers in this group: {0}", item.Count());
  10.                     Console.WriteLine(outGrp);
  11.                     writer.WriteLine(outGrp, true);
  12.                     Console.WriteLine("Numbers:");
  13.                     writer.WriteLine("Numbers:", true);
  14.                     foreach (var member in item)
  15.                     {
  16.                         Console.WriteLine(member);
  17.                         writer.WriteLine(member, true);
  18.                     }
  19.                 }
  20.             }
Oct 16 '13 #1

✓ answered by vinsbg

Oh, is just one break; into second foreach.

1 1255
vinsbg
4
Oh, is just one break; into second foreach.
Oct 16 '13 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Silvia | last post by:
Hello I have a listview with images, and when I select one image I can delete the image, bu I produce an error, say "the process cannot access the file D:\imagesDicomitzador\142617379\image1.bmp...
3
by: Paul | last post by:
Is it possible to delete a file on a client side machine using VB/JAVA script? My website allows the user to upload a file to the website and after that I would like to delete the file on their...
4
by: Michael K. | last post by:
Hi there I am having trouble deleting an uploaded file that I have just written to disc. I am using the SaveAs method of a HttpPostedFile to write the file to disc, then straight after I'm...
3
by: facicad | last post by:
I would like to know if as event before delete file exist. My probleme is with FileSystemWatch, it is only Deleted event, and went I want copy for bakup my file, the file do not exist :(
2
by: TOI DAY | last post by:
Hi all, How can I delete the file on the server after the user download it? For example: I have file name "123.txt" on a server, I copy it to "ABC.txt", then allow uer download the...
3
by: Parag Gaikwad | last post by:
Hi, I need to delete files across the network using web client (IE 6.x) in Win 2003 - IIS 6.0 environment. Can someone please suggest an approach I can use to acheive this. Will using FSO do...
5
by: wo20051223 | last post by:
Deleting some files with C# fails with "Access to the path 'X' is denied". I have files copied from a CD that I burned (and not locked by a process) and a text file that I created in Windows...
1
by: ABC | last post by:
Is there any best solution automatic delete file within the special time? My web application can generate many pdf files for users. Because there are many users, I need to control the total...
1
by: Tod Birdsall | last post by:
I am using Microsoft Office Document Imaging (MODI) with great success. However, when execute the following code, I get the error "The process cannot access the file 'myFile.tif'" (File name has...
4
by: id10t error | last post by:
Hello, I am making a program that will not have an user interaction to delete certian files. I found this line of code. My.Computer.FileSystem.DeleteFile("C:\POLLJP.DWN",...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.