Skip to main content

Timeline for Sorting files using a bash script

Current License: CC BY-SA 3.0

16 events
when toggle format what by license comment
Jun 23, 2016 at 23:22 vote accept JavaFreak
Jun 23, 2016 at 23:22
Jun 15, 2016 at 6:31 comment added John1024 @roaima That link is very interesting. Thanks. Cygwin knows what the "ideal" behavior would be. And, they know that the actual behavior, for good reasons or otherwise, is quite different.
Jun 13, 2016 at 9:07 comment added Chris Davies Looks like Cygwin's already thinking about this, see cygwin.com/cygwin-ug-net/using-textbinary.html, but it doesn't really default to DWIM. Also, thinking harder about the problem, libc wouldn't really know whether a file was text or binary unless binmode() had been used - in which case Cygwin already handles it correctly
Jun 13, 2016 at 7:51 comment added Chris Davies That's an interesting suggestion. An environment variable to define "nonstandard" line endings perhaps, thereby handling not only Windows but also Mac in one go. ALLOW_LINE_ENDINGS='\r\n' handled by libc and recommended being set as an appropriate default at login. Mind you, how long would it be before script writers started intentionally abusing it as a shortcut?
Jun 12, 2016 at 19:57 comment added John1024 @roaima Very true. Since Windows is not going away, I think it is unfortunate that Unix tools do not have an option to ignore \r characters.
Jun 12, 2016 at 19:43 comment added Chris Davies One can also reproduce the line-endings problem in Notepad by not providing a newline at the end of the cat alpha_sorted.txt. Empirically bash is happy to infer the newline, and this then also leads to the alpha_sorted.txt\r vs alpha_sorted.txt mismatch that triggers the reported problem
Jun 12, 2016 at 18:12 history edited John1024 CC BY-SA 3.0
added 772 characters in body
Jun 12, 2016 at 18:03 comment added John1024 @JavaFreak I just transferred the info showing the no-such-file error to your question. As you have found out, StackExchange takes its format seriously. The idea is that the question is to contain a complete question and the answers are to contain only answers.
Jun 12, 2016 at 17:56 comment added John1024 @JavaFreak Looking at your post, my first guess is that the problem has to do with DOS/Windows line-endings. DOS ends a line with \r\n. Unix ends a line with just \n and treats \r like a valid (but invisible) character. This causes an endless number of subtle problems. Please try converting your script.sh to Unix line endings using a tool like dos2unix. If you use a native Unix editor (nano is good for beginners), then you will avoid this as well as other subtle issues.
Jun 12, 2016 at 14:53 comment added JavaFreak Check my comment below if possible sir
Jun 12, 2016 at 14:33 comment added Alex Stragies @JavaFreak On a linux machine, you would mark the script as executable with chmod +x scriptname.sh, and then run it with ./ scriptname.sh
Jun 12, 2016 at 13:12 comment added JavaFreak I do have a small problem, iif i was to put the commands in a text file and change it to .sh how am i suppose to run it since i have been trying to do so for the past few hours and it is not working am using cyguin
Jun 12, 2016 at 5:16 comment added John1024 @heemayl Very true. I changed it to -k2,2. While the second 2 is superfluous here, you are probably right that it is better practice to be explicit.
Jun 12, 2016 at 5:15 history edited John1024 CC BY-SA 3.0
added 4 characters in body
Jun 12, 2016 at 3:32 comment added heemayl John, slight nitpicking, -k2 specifies to start sorting from column 2 to till end, not only on the column 2 (in this case which is only what left but again hey :) )
Jun 12, 2016 at 1:58 history answered John1024 CC BY-SA 3.0