Search code examples
regexshellunixtexttext-manipulation

How to extract values from a text file using a script?


If I have a file with the contents as below:

field1=value1,field2=value2,field3=value3,field4=value4,field5=value5,..;(new line)
field1=value1.1,field2=value1.2,field3=value1.3,field4=value1.4,field5=value1.5,...; (new line)
.....
....
...

Each line ends with semi-colon and a new line character.

How can I extract and store(or display) in the below format?

enter image description here


Solution

  •   string[] lines = System.IO.File.ReadAllLines(@"C:\Users\Public\TestFolder\WriteLines2.txt");
    
    
      foreach (string line in lines)
            {
               String[] Contain=line.Split(",");
                 foreach (string ordata in Contain)
                 {
                      String[] data=ordata.Split("=");
                      var Value=data[1];
                   // Write Code for store Data
                  }
            }
    

    above code helps you to make it working.