Once a CSV
file is loaded, as below, how is the data then sorted?
PS /home/nicholas/powershell/csv>
PS /home/nicholas/powershell/csv> $words = Import-Csv -Path ./sort.csv
PS /home/nicholas/powershell/csv>
PS /home/nicholas/powershell/csv> $words
symbol code word morse code phonetic
------ --------- ---------- --------
A Alfa/Alpha ● ? AL FAH
B Bravo ? ● ● ● BRAH VOH
C Charlie ? ● ? ● CHAR LEE
D Delta ? ● ● DELL TAH
E Echo .● ECK OH
F Foxtrot ● ● ? ● FOKS TROT
G Golf ? ? ● GOLF
Z Zulu ? ? ? ? ? ZOO LOO
H Hotel ● ● ● ● HOH TELL
I India ● ● IN DEE AH
J Juliett ● ? ? ? JEW LEE ETT
K Kilo ? ● ? KEY LOH
L Lima ● ? ● ● LEE MAH
M Mike ? ? MIKE
N November ? ● NO VEMBER
O Oscar ? ? ? OSS CAH
I India ● ● IN DEE AH
P Papa ● ? ? ● PAH PAH
Q Quebec ? ? ● ? KEH BECK
S Sierra ● ● ● SEE AIRRAH
R Romeo ● ? ● ROW ME OH
T Tango ? TANG OH
U Uniform ● ● ? YOU NEE FORM
V Victor ● ● ● ? VIK TAH
W Whiskey ● ? ? WISS KEY
X X-ray ? ● ● ? ECKS RAY
Y Yankee ? ? ● ● YANG KEY
Z Zulu ? ? ? ? ? ZOO LOO
PS /home/nicholas/powershell/csv>
PS /home/nicholas/powershell/csv> $words | sort 'code word'
/usr/bin/sort: cannot read: 'code word': No such file or directory
PS /home/nicholas/powershell/csv>
PS /home/nicholas/powershell/csv> sort $words
/usr/bin/sort: cannot read: '@{symbol=A; code word=Alfa/Alpha; morse code=● ?; phonetic=AL FAH}': No such file or directory
PS /home/nicholas/powershell/csv>
PS /home/nicholas/powershell/csv> help sort
PS /home/nicholas/powershell/csv>
see also:
https://devblogs.microsoft.com/scripting/use-powershell-to-sort-csv-files-in-order/
which has similar examples, except that the data is sorted as its imported.
original data as:
nicholas@mordor:~/powershell/csv$
nicholas@mordor:~/powershell/csv$ head sort.csv
symbol,code word,morse code,phonetic
A,Alfa/Alpha,● ?,AL FAH
B,Bravo,? ● ● ●,BRAH VOH
C,Charlie,? ● ? ●,CHAR LEE
D,Delta,? ● ●,DELL TAH
E,Echo,.●,ECK OH
F,Foxtrot,● ● ? ●,FOKS TROT
G,Golf,? ? ●,GOLF
Z,Zulu,? ? ? ? ?,ZOO LOO
H,Hotel,● ● ● ●,HOH TELL
nicholas@mordor:~/powershell/csv$
which was copy/pasted from a website.
get members shows:
PS /home/nicholas/powershell/csv>
PS /home/nicholas/powershell/csv> $words = Import-Csv -Path ./sort.csv
PS /home/nicholas/powershell/csv>
PS /home/nicholas/powershell/csv> $words | Get-Member
TypeName: System.Management.Automation.PSCustomObject
Name MemberType Definition
---- ---------- ----------
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
code word NoteProperty string code word=Alfa/Alpha
morse code NoteProperty string morse code=● ?
phonetic NoteProperty string phonetic=AL FAH
symbol NoteProperty string symbol=A
PS /home/nicholas/powershell/csv>
which is as expected.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…