[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Sorting elements *and* knowing where each one has been put



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Lee Winter <lee.j.i.winter@gmail.com> writes:

> In the discussion above you persist in mixing the sort function with
> the sort command.  They are not the same, so please be more careful in
> your descriptions of what it is you want to accomplish.
>
> To sort with a function, such as is found in many programming
> languages, you should create a data structure containing the value to
> be sorted (the "key") and any audit/trance information you need about
> the position of each item prior to the sort.  After sorting such data
> structures with the language's sort() function you will be able to
> identify where each value started and ended.
>
> To sort with a command, such as is found in many command-line
> envoronments, you should create lines of text, each containing the
> value to be sorted (the "key") and followed by any audit/trace
> information you need about the position of each item prior to the
> sort.  After sorting the text lines with the command-line
> environment's text sorting utility you will be able to identify where
> each value started and ended.
>
> The above descriptions answer the question you asked.  But it appears
> to me that the answer you need is related to a different question.
> What do you need to do with the values after they are sorted?  If you
> have both the initially ordered list and the sorted list, why do you
> care where things started as long as they are where they need to be
> when you are done?

Thanks for your answer, Lee.

Sorry if, after having read my text, you think that I am mixing the
sort function and the sort command. It was not my intention, as they
are different things, both to you, and to me.

I am here sorting with a _command_, this one being `sort'. Your idea
of appending to each key, e.g. a number, is great. I had not thought
about it. The question is now: how to append to lines some text? Okay,
generating numbers so that n_1 < n_2 < ... < n_n is not difficult, but
how can I redirect them to each line of a flux using bash?

The problem is not so complex. I have files with names which are only
constituted by numbers. Each file contains exactly one e-mail, but the
`Received' field of each e-mail is not linked to the name of the
file. For example, if I have three files, say `1' , `2' and `3', each
containing an e-mail with headers, displaying only the `Received'
field on each could give, for example:

File 1 -> Received 2 Jan 2009
File 2 -> Received 7 Sep 2005
File 3 -> Received 3 Feb 2009

Once I have sorted the dates, and as the global `cat *' takes account
of the order between numbers in the set of the integers (i.e. `cat *' is
equivalent to `cat 1' and `cat 2' iff the current folder only contains
`.', `..', `1' and `2'), I can then sort the dates. Before the
sorting, the n-th date is related to the n-th e-mail's headers'
`Received' field. After the sort, it may have completely no
link. Consequently, I need to know which e-mail was received first,
and consequently which date was moved at the beginning of the
list.

I hope I have been clear. I now need to be able to append increasing
number to each line of the flux _before_ the sorting. Do you have an
idea about how to implement this in bash?

Thanks.

- -- 
Merciadri Luca
See http://www.student.montefiore.ulg.ac.be/~merciadri/
- -- 

Don't have too many irons in the fire.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.8 <http://mailcrypt.sourceforge.net/>

iEYEARECAAYFAktkExoACgkQM0LLzLt8MhzhxwCeIIgQnuvbDfVRoLvJgmgkY3qn
6sUAn2Su5tf6iHQfvi43ZJWAebWml6lm
=W08e
-----END PGP SIGNATURE-----


Reply to: