"cat" command no output using Catalina, and "sort" not sorting.

I'm trying to sort a text file.

In the past, I've opened a Terminal window and issued the following command:

“cat jumbled.txt | sort > sorted.txt”


Now I get the following Error: "sort: illegal byte sequence"


Attempting to troubleshoot, I tried the command: cat jumbled.txt

which used to print the contents of the text file to the screen. BUT NOW I GET NO OUTPUT!


OK, let's try the "sort" command directly:

"sort jumbled.txt" here's my screen output:

R Ð5/04/2021guez08@gmail.comom


OK, so let's just try the "sort" command and redirect to a file.

"sort jumbled.txt > sorted.txt" yields a file ok, BUT IT'S NOT SORTED.


What's going on with the command line utilities?

THEY'RE USELESS in CATALINA



MacBook Pro

Posted on May 24, 2021 5:25 PM

Reply

Similar questions

11 replies

May 25, 2021 5:03 AM in response to victor265

victor265 wrote:

Have you ever seen this behavior before?

For about 30 years. I’m afraid the only option here is to use a powerful text editor that can make sense out of the encoding and line endings. I suggested BBEdit because, as difficult as it may be to use, it is infinitely easier than trying to do the same in vim or emacs. You could use a binary editor too, but that would require you to personally have all that knowledge.


Simple text editors like TextEdit or Notepad simple can’t handle this.

May 24, 2021 6:29 PM in response to etresoft

Thanks for the reply. OK, I've installed BBEdit, but can't find how to use it to check the encoding used in my text file.

I looked at "View/get info", found nothing of interest, and looked at all the menus. no way to check encoding that I can see.

help offers to "Reopen using encoding..." but I don't want to change it until I know what I've got to start with.


???

May 24, 2021 6:52 PM in response to victor265

Etresoft: OK, so taking the initiative here, I cut and pasted my unsorted list into a new file using the Mac "TextEdit" program.

When saving, you can select the encoding type. I let it use the default UTF-8 encoding. the file shows up as charset=us-ascii when I check it using the "file -I" command.

Still have the same problems: "cat" won't display it, and "sort" won't sort it.

May 25, 2021 8:31 AM in response to etresoft

Well, lucky for me, Notepad revealed the lack of line feeds, which told me what I had to do. BBEdit may be able to show that it was us-ascii, but that didn’t tell me the solution. FYI: When BBEdit opened the file it looked like it had line feeds. And I never did figure out how to get BBEdit to reveal the encoding. But I’m done, problem solved. I have good notes for the future.

Thanks again


vic

May 24, 2021 8:18 PM in response to victor265

etresoft:

OK, so I fired up Parallels and copied the text file to Windows, went to a command prompt and issued the command:

"type scrambled.txt"


and guess what? It STILL only displayed the last line of the file.

So, THAT's good news that my MacOS isn't messed up. So what's the problem?


Next I opened the file with Window's Notepad, and GUESS WHAT?!

THERE WERE NO LINEBREAKS!!


Why didn't that show up in Mac's TextEdit program? Each Email address had it's own line, so I had no way of knowing there weren't line breaks (CR's) already in the text.


So I used Notepad to manually add a linefeed after each address, and the "Type" command in the command shell worked as expected.


So I moved the file back to the Mac directory and using the Terminal window the "cat" command worked as expected.

So, then I did a "sort scrambled.txt >sorted.txt" and it all sorted fine.


Have you ever seen this behavior before?


Thanks for your help.


Vic

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

"cat" command no output using Catalina, and "sort" not sorting.

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.