Hacker Read top | best | new | newcomments | leaders | about | bookmarklet login

In addition... "PUT commands write to a file, GET commands read the file back, sort and reduce the data, then return the file"

I guess the author had to add the sort/reduce to "prove" his point...



sort by: page size:

I am thankful to you for highlighting this part of the long paper. That completely wrong assertion (the input to sort is infile, nothing more, nothing less) casts the rest of the content in doubt (at least it does to me).

Well, if you really want to golf it, you can just write:

  File.write ARGV[1], IO.readlines(ARGV[0]).sort.join('\n')
;)

> I want to move a thousand files beginning with 'UTR-77' and ending with '.csv'

1. Use a file manager with stable sorting [1] (I use Thunar which does this, but I suspect lots of file managers keep the sort order stable).

2. Sort by type.

3. Sort by name.

4. Select the first file named UTR-77.

5. Scroll to the last file, and Shift+Click it.

6. Cut then paste to your desired directory.

[1] - https://en.wikipedia.org/wiki/Sorting_algorithm#Stability


It's like the old programming interview, someone sits down and is asked to write a program that sorts a file containing a list of 100 random numbers.

The programmer enters the UNIX command sort -n numbers


'cat christmas_list.txt | sort > christmas_list.txt'

the above is wrong. that will clobber the file.


Exact same problem. :)

At least that is sometimes written as Shell's sort.


> s='du -sh * | sort -h'

Quick shoutout, you should probably alias to 'du -sh -- *'. Otherwise file names starting with '-' are interpreted as input for your command.


When the input is large enough, GNU `sort` writes the input in chunks to multiple temporary files, sorts the individual files, and then merges the result for output.

https://unix.stackexchange.com/questions/279096/scalability-...


Curious, in case I'm missing something. Is what you've written equivalent to the following, or is there a reason for the pipe?

sort in.txt > out.txt


>Or reverse sort till the end of the file with !Gsort -r^M etc.

Right. Or flip the case of a section of text, even of an arbitrary block of lines demarcated by marks set by vi(m) commands like ma and mb and the like, by filtering it through tr.

Or filter another section through sed or awk or even through a Unix pipeline, to do whatever you want.

And with just a little practice, you can become fluent and fast with all of this, and it improves your productivity a lot, apart from being fun and creative.


a couple of mistakes and comments:

* "File>new" can be done by ':enew'

* top of the file is 'gg' and not just 'g'

* bottom of the file is 'G' and not 'GG' ;)

* in addition to ':20<CR>' you can use just '20G' to go to line 20

* to sort all of the file use ':%!sort<CR>', no need to use '0,$'


> Doing cat from left to right helps readability - it's important.

People may balk because it's unfamiliar, but this is syntactically legal:

    < logs.txt sort | uniq > /dev/null
That is, the redirection customarily goes at the end, but it doesn't have to.

EDIT: Also, in this specific case, the "sort" command can take a file argument, so you can also do this:

    sort logs.txt | uniq > /dev/null

"The unix command line ('cat foo.txt | sort | uniq -c | sort -rn') is wonderfully concise and powerful". And yet, contrary to the author's assertion, it can be made even more concise without sacrificing the power:

sort foo.txt | uniq -c | sort -rn


I know it's not exactly an unknown command, but I didn't know about "sort" until last week.

It's freaking fast and convenient, sorts hadoop reduce results like a champ.


If you're using gnu coreutils: sort -u foo.

> We also have Timsort.

And Shellsort!


> grep and sort tasks to make sense of things

This.

grep + sort + awk = unbelievable single person task management effectiveness. And it was right under my nose all the while.

I've dumbed my version even further, I just use numbers. every line starting with 1 is highest Priority and so on.

another important piece i needed was a pointer to where i last left off. I just use double underscores "__". next time just open and search for 2 underscores and start right off.

Works everywhere.


Ruby:

  array = IO.readlines ARGV[0]
  array.sort!
  File.write ARGV[1], array.join("\n")
edit: get input and output file names from command line

> sorting with skipped headers is a mess

I like these command line tools, but I think they can cripple someone actually learning programming language. For example, here is a short program that does your last example:

https://go.dev/play/p/9bASZ97lLWv

next

Legal | privacy