Windows 10: sorting columns in CSV file with powershell

Discus and support sorting columns in CSV file with powershell in Windows 10 Software and Apps to solve the problem; I have a csv file with 1600 lines from which top ten lines given below N,EQ,ADANIPORTS,ADANI PORT & SEZ... Discussion in 'Windows 10 Software and Apps' started by lvgandhi, Aug 25, 2018.

  1. lvgandhi Win User

    sorting columns in CSV file with powershell


    I have a csv file with 1600 lines from which top ten lines given below
    N,EQ,ADANIPORTS,ADANI PORT & SEZ LTD,384.5,385,387.8,375,376.75,792818726.1,2085488,Y, ,40850,452.35,350.45
    N,EQ,ASIANPAINT,ASIAN PAINTS LIMITED,1394.75,1395,1411,1385.05,1393.5,1284559258,919355,Y, ,36117,1490.6,1090.1
    N,EQ,AXISBANK,AXIS BANK LIMITED,631.75,638.05,643.4,634,639.9,9599936309,15035968,Y, ,144038,644.65,447.5
    N,EQ,BAJAJ-AUTO,BAJAJ AUTO LIMITED,2685.55,2683.9,2697,2664,2682.25,1476618943,551229,Y, ,23611,3468.35,2605
    N,EQ,BAJAJFINSV,BAJAJ FINSERV LTD.,7092.1,7092,7129,7025.25,7050.65,909166393.3,128111,Y, ,19707,7200,4500
    N,EQ,BAJFINANCE,BAJAJ FINANCE LIMITED,2893.85,2892,2943.4,2891.05,2916.6,3884349778,1327710,Y, ,52356,2943.4,1511.2
    N,EQ,BHARTIARTL,BHARTI AIRTEL LIMITED,369.9,370,370.8,365,368.95,768282183.8,2089422,Y, ,26515,564.8,331
    N,EQ,BPCL,BHARAT PETROLEUM CORP LT,357.75,358.25,362,353.5,356.95,1738725370,4865929,Y, ,77863,551.55,353.5
    N,EQ,CIPLA,CIPLA LTD,657.95,658,658,645,651.2,1235846442,1904031,Y, ,38575,665,507.2
    N,EQ,COALINDIA,COAL INDIA LTD,289.05,287.85,293.6,287.8,291,791484837,2713583,Y, ,55421,316.95,235.85

    I wanted to sort 10 the column in descending order so that top 20 I can find out.
    The file name is Pd240818.csv
    my powershell code is as below.
    # To remove unwanted few lines
    sls ",BE,",",EQ," .\Pd240818.csv | select -exp line | Where-Object {$_ -notmatch ',EQ, ,'} > .\temp.csv
    #Sorting line is as follows
    gc .\temp.csv | Where-Object {$_ -notmatch 'MKT,'}|%{$_.split(",")[9]}|Sort-Object -Descending| Select-Object -first 20 > temp.txt
    Sorted

    I get temp.txt as follows
    99988.7
    99896.5
    9989273.6
    99769.75
    996134.55
    9933960.45
    99228.65
    99199.95
    989418.15
    988423057.7
    9884111.1
    98572145.2
    982146.5
    981497584.9
    97982.75
    9786178.9
    9775915.05
    9760482.5
    97384498.85
    971033.85

    Where as if I sort the same column in excel, I get as below.
    28818819313 9599936309 8459873415 6175554483 5889553012 5690666055 5439638100 5121938441 5079530750 5042021707 4972762046 4889394601 4742835986 3884349778 3690976213 3486309023 3388956937 3336437125 3206801588 3114870807 Where am I doing wrong. How to correct it?

    :)
     
    lvgandhi, Aug 25, 2018
    #1

  2. Sorting column of mixed format data

    You would need to do this:

    • Create an extra column to the right of plot numbers.
    • Copy the plot numbers from the left to the right column.
    • Remove all letters from the left column.
    • Remove all numbers from the right column.
    • Place a space or an exclamation mark into all empty cells in the right column.
    • Sort the list against the left plus the right column.
    • Replace each exclamation mark with a space.
     
    Frederik Long, Aug 25, 2018
    #2
  3. Berton Win User
    Sorting Explorer columns by multiple criteria


    I also haven't seen the capability of multiple sort criteria in many versions of Windows Explorer or the later [in Win8/8.1/10] File Explorer. Each column visible can be sorted in ascending or descending order, clicking a different column changes the view strictly to that arrangement. Generally the columns are sorted alphabetically with Folders first. Compressed/zip files are usually between Folders and files except in Type where they will be at either end of the list.
     
    Berton, Aug 25, 2018
    #3
  4. dalchina Win User

    sorting columns in CSV file with powershell

    CSV files used to open in Excel....not now!


    Hi, you say Excel is installed. Does it run normally?

    You can't find Excel in (an unspecified) list of applications. I don't know which list that is for sure.

    For example, in the list related to:
    - rt click a file. Open With
    - this list:

    sorting columns in CSV file with powershell [​IMG]

    - this list:

    sorting columns in CSV file with powershell [​IMG]


    - some other list...

    If Excel does not appear in the above, I suggest you repair your office installation.

    Maybe the above gives you some ideas. Otherwise please post a screenshot of where you think you should see it but don't. Thanks.
     
    dalchina, Aug 25, 2018
    #4
Thema:

sorting columns in CSV file with powershell

Loading...
  1. sorting columns in CSV file with powershell - Similar Threads - sorting columns CSV

  2. Powershell: How to separately data in 1 column to others columns with header ?

    in Windows 10 Customization
    Powershell: How to separately data in 1 column to others columns with header ?: Dear supporter, Thank you for your visit, I'm a very new with Powershell data array, I have a question and I hope you can help me: I have a .csv file with 3 column, "Auditdata" is one of them and it contains too much data and I can't filter them. its data in format...
  3. Create csv file

    in Windows 10 Network and Sharing
    Create csv file: How do I create a csv file from, my contacts? https://answers.microsoft.com/en-us/windows/forum/all/create-csv-file/5f2fe32c-02eb-4a33-8f07-ff325c25e4a1
  4. exporting contacts from gmail to csv file then importing the .csv file to outlook

    in Windows 10 Network and Sharing
    exporting contacts from gmail to csv file then importing the .csv file to outlook: I have a dell 15-3567 win 10 OS and Outlook 2019 I am trying to exporting contacts from gmail to a csv file on my desktopwhich I have done sucessfully, then importing the .csv file into outlook. to use in outlook E-mail in Outlook 2019 ,when I choose file, open &...
  5. Excel: how to sort columns

    in Microsoft Office and 365
    Excel: how to sort columns: [img] Hi I I understand why those columns are sorted the way they are, but I cant sort them the way I want. ie - I would like CS_S all the way left, CS_E is in column 3, etc. I have tried a bunch of diff options under data>sort, but regardless of what I try, I cant get...
  6. Windows Explorer not showing "Sort by" columns

    in Windows 10 Network and Sharing
    Windows Explorer not showing "Sort by" columns: I can't recall exactly when the issue began, but for the past while many files have been missing their "Sort by" columns. I only see the three tabs: "ascending," descending," and "choose columns." Clicking the "choose columns" opens up the checkbox menu as usual, but none of...
  7. Preview csv file no avaiable

    in Windows 10 Network and Sharing
    Preview csv file no avaiable: I can't preview csv file on my laptop . This message is "No preview avaiable" I have installed Office 365 64bit , win 10 pro 64 bit. Excel version 16.0.11328.20420 . Anyone can help me ? Thanks...
  8. Powershell script to add a date to each row of a csv.

    in Windows 10 Customization
    Powershell script to add a date to each row of a csv.: Hi all, struggling to get a powershell script working so I'm wondering if somebody would be kind enough to help, hopefully it's something simple but my experience with powershell isnt that great although I am learning heaps. I have a simple database (a csv file) called...
  9. Help needed for working with csv file in powershell

    in Windows 10 Software and Apps
    Help needed for working with csv file in powershell: I have a csv file, I need to extract a few columns from that file and create a csv file with those columns. My csv file is NBN.csv. I tried to extract a few columns in new order. I succeeded in that. But out put is not a csv file as shown below. [img] How to make the out...
  10. Sorting Explorer columns by multiple criteria

    in Windows 10 Support
    Sorting Explorer columns by multiple criteria: Hi, I used to sort files in the w10 explorer using detailed view by date and then, by left clicking on name, the directories by name. For some reason, this does not work any more. Does anyone have an idea how I can do this again, as it worked fine until recently....

Users found this page by searching for:

  1. powershell sort csv number with commas

    ,
  2. sort csv by first column powershell

    ,
  3. powershell sort csv file by multiple columns

    ,
  4. powershell csv sort by multiple columns,
  5. sort property columns csv powershell