views:

428

answers:

1

All I did was ls to a file, then ran a simple awk print. I'm new to both PowerShell and Awk, but the output is obsviously not what's expected. Can anyone explain this? Does it have something to do with the format of the file?

PS C:\Documents and Settings\lmoser\My Documents\Test> awk '{ print }' lsfiles.txt > awkedlsfile.txt
PS C:\Documents and Settings\lmoser\My Documents\Test> cat lsfiles.txt
----                -------------     ------ ----
-a---         10/8/2009  10:32 AM          0 file1.txt
-a---         10/8/2009  10:32 AM          0 file2.txt
-a---         10/8/2009  10:32 AM          0 file3.txt
-a---         10/8/2009  10:32 AM          0 file4.txt
-a---         10/8/2009  10:32 AM          0 file5.txt
-a---         10/8/2009  10:32 AM          0 file6.txt
-a---         10/8/2009  10:32 AM       2164 lsfiles.txt
PS C:\Documents and Settings\lmoser\My Documents\Test> cat awkedlsfile.txt
----                -------------     ------ ----
??????         ? ????  ?  ? ??? ??            ?????????
 ??
-a---         10/8/2009  10:32 AM          0 file2.txt
??????         ? ????  ?  ? ??? ??            ?????????
 ??
-a---         10/8/2009  10:32 AM          0 file4.txt
??????         ? ????  ?  ? ??? ??            ?????????
 ??
-a---         10/8/2009  10:32 AM          0 file6.txt
??????         ? ????  ?  ? ??? ??       ???? ???????????
 ??
?
+2  A: 

Is your awk unicode-aware? I suspect not. If that is the case try this:

awk '{ print }' lsfiles.txt | Out-File awkedlsfile.txt -encoding ASCII

By default, PowerShell redirects to file using Unicode format. Essentially using ">" is just a shortcut for "| Out-File {path} -Encoding Unicode"

Keith Hill
Basically the right idea. I piped the original ls to an ASCII encoded file, then awk worked as expected.
L. Moser