Text to column issues

This topic contains 5 replies, has 5 voices, and was last updated by  JohnM 3 months, 2 weeks ago.

  • Author
    Posts
  • #98124

    chad volz
    Participant

    Im pulling a csv file from a putty session output. Im trying to get it properly formatted into columns but since the output doesnt have any commas or tabs and each row has different number of spaces my text to column ps1 doesnt format it correctly unless I do some manual editing of the file which this has to be an automated process due to the amount of files so Im trying to figure out how to get my powershell script to do it correctly. Below is the data I have in .csv, running an import-csv will return this and you can see the space situation Im talking about

    Name                   Size  Thin Provisioning  Data Reduction  Total Reduction  Volume   Snapshots  Shared Space  System  Total  
    ----------------------------------------------------------------------------------------------------------------------------------
    Development_b_001      8T    57%                5.9 to 1        13.7 to 1        548.64G  45.20G     -             -       593.84G
    Production_b_001       8T    36%                3.2 to 1        5.0 to 1         1.57T    0.00       -             -       1.57T  
    
  • #98127

    js
    Participant

    This doesn't work?

    import-csv file.csv | format-table -autosize
    
  • #98131

    Jon
    Participant

    You might want to try "convertfrom-string"

    Check this out for some good examples

  • #98137

    Joel Sallow
    Participant

    I would look into the possibilities with ConvertFrom-String 🙂

  • #98149

    chad volz
    Participant

    Yeah I found ConvertFrom-String while I was googling just struggling to make the -templatefile now but If I can figure this out I think I got it I just dont know the proper syntax to get it just yet. Tried below but its not working how I thought it would.

      {Name*:*}                   {Size*:*}  {Thin Provisioning*:*}  {Data Reduction*:*}  {Total Reduction*:*}  {Volume*:*}   {Snapshots*:*}  {Shared Space*:*}  {System*:*}  {Total*:*}
    
  • #98151

    JohnM
    Participant

    Your template is a bit off.

    instead of your string like this .....
    Yours:
    {Name*:*}                   {Size*:*}  {Thin Provisioning*:*} 
    
    Try this instead based upon the data:
    
    Name                   Size  Thin Provisioning  Data Reduction  Total Reduction  Volume   Snapshots  Shared Space  System  Total  
    ----------------------------------------------------------------------------------------------------------------------------------
    {name*:Development_b_001}      {Size:8T}    {Thin_provisioning:57%} 
    {name*:Production_b_001}       {Size:8T}    {Thin_provisioning:36%}
    
    
    

    Make sure you have enough samples to provide to the Convertfrom-string engine in your template file. I would use at least 3 lines, and if they each have slightly different sizes/values that is better.

    I also found an earlier post in this forum:
    https://powershell.org/forums/topic/need-to-read-a-file-and-store-it-in-a-variable/#post-91695

You must be logged in to reply to this topic.