Text to column issues

Welcome Forums General PowerShell Q&A Text to column issues

This topic contains 5 replies, has 5 voices, and was last updated by

 
Participant
1 year, 1 month ago.

  • Author
    Posts
  • #98124

    Participant
    Topics: 2
    Replies: 1
    Points: 0
    Rank: Member

    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
    Topics: 21
    Replies: 585
    Points: 1,118
    Helping Hand
    Rank: Community Hero

    This doesn't work?

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

    Participant
    Topics: 13
    Replies: 219
    Points: 90
    Rank: Member

    You might want to try "convertfrom-string"

    Check this out for some good examples

  • #98137

    Participant
    Topics: 2
    Replies: 428
    Points: 835
    Helping Hand
    Rank: Major Contributor

    I would look into the possibilities with ConvertFrom-String 🙂

  • #98149

    Participant
    Topics: 2
    Replies: 1
    Points: 0
    Rank: Member

    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

    Participant
    Topics: 1
    Replies: 40
    Points: 44
    Rank: Member

    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

The topic ‘Text to column issues’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort