Note that there are some explanatory texts on larger screens.

plurals
  1. POCombine text file lines c#
    primarykey
    data
    text
    <p>I'm having difficulty combining some lines in a comma delimited text file if the first field is the same. This is my file:</p> <pre><code>Area 1 Chiller Grids aB aN and a1 a6,test,1,Ground Floor Framing Area 1 Chiller Grids aB aN and a1 a6,test,2,Monorails West Area 1 Chiller Grids aB aN and a1 a6,test,6,Roof Framing West Area 1 Chiller Grids aB aN and a1 a6,test,11,Bullnose West Area 2 Office Grids aN zA and a1 a6,101806,3,First Floor Framing East Area 2 Office Grids aN zA and a1 a6,101806,5,Mezz Floor Framing Area 2 Office Grids aN zA and a1 a6,101806,7,Roof Framing East Area 2 Office Grids aN zA and a1 a6,101806,9,First Floor Ceiling Area 3 Bridge Grids yA yE and a1 10x,101807,4,Link Floor Framing Area 3 Bridge Grids yA yE and a1 10x,101807,8,Link Roof Framing Area 3 Bridge Grids yA yE and a1 10x,101807,10,Bridge Catwalks Area 3 Bridge Grids yA yE and a1 10x,101807,13,Stair 1 </code></pre> <p>I need the output to be this:</p> <pre><code>Area 1 Chiller Grids aB aN and a1 a6,test,1-2-6-11,Ground Floor Framing-Monorails West-Roof Framing West-Bullnose West Area 2 Office Grids aN zA and a1 a6,101806,3-5-7-9,First Floor Framing East-Mezz Floor Framing-Roof Framing East-First Floor Ceiling Area 3 Bridge Grids yA yE and a1 10x,101807,4-8-10-13,Link Floor Framing-Link Roof Framing-Bridge Catwalks-Stair 1 </code></pre> <p>How can I go about this? I've tried some linq code I found on here but it doesn't quite get what I want and I'm not sure how to make it do it:</p> <pre><code> var a = System.IO.File.ReadAllLines(@"X:\Steelcad_Project_Files\" + dir + "\\manager1.txt"); var b = System.IO.File.ReadAllLines(@"X:\Steelcad_Project_Files\" + dir + "\\manager.txt"); var query = from bline in b let parts = bline.Split(',') group parts[2] by parts[0] into bg join aline in a on bg.Key equals aline select aline + "," + string.Join("-", bg.ToArray()); System.IO.File.WriteAllLines(@"X:\Steelcad_Project_Files\" + dir + "\\result.txt", query.ToArray()); </code></pre> <p>Where the manager1 file only has the first field in it, like so:</p> <pre><code>Area 1 Chiller Grids aB aN and a1 a6 Area 2 Office Grids aN zA and a1 a6 Area 3 Bridge Grids yA yE and a1 10x </code></pre> <p>I would like, if possible, to only use 1 file though. Any help would be much appreciated. Thanks</p> <p>EDIT: Is it possible to sort the lines based on line 0 and then line 2? If it was 1-11-15-2-6 can it be rearranged to 1-2-6-11-15 but keeping all the Area 1's together etc?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload