Re: sort a file.
- From: Bit Twister <BitTwister@xxxxxxxxxxxxxxxx>
- Date: 29 Mar 2007 01:08:18 GMT
On Thu, 29 Mar 2007 02:35:18 +0200, Mr. X. wrote:
Hello,
I need a program in unix (C)
that do : getting a file, and sort it (by lines).
No, you do not sort by lines, you sort the data.
It need to use sort command, and many process (by fork ...),
that each of the processes do sort of 100 lines (with temporary file of
pid).
and after all the processes are done - I need to merge the sorts into one
big output file.
I want to sort specific lines,
is it sort -k ?
I need help of that function (sort -k1,20 doesn't work : line 1 to 20).
If you were to do a man sort, you might notice
-k, --key=POS1[,POS2]
start a key at POS1, end it at POS2 (origin 1)
Now let's say you wanted to sort /etc/passwd by user id.
bittwister:x:1500:1500:Bit Twister:/home/bittwister:/bin/bash
junk:x:500:500:Junk Account:/home/junk:/bin/bash
^ ^
| |
UID----' `----- GID
As you can see, the uid field is not in the same column.
If you make the field terminator a : then you can use the -k switch to
pick which key/field (3) to be used during sorting.
So you have to first decide if your data is in fixed columns or in a
variable format. Then you decide which fields/columns to pick for
your sort criteria.
For extra points you might want to read
http://tldp.org/LDP/abs/html/index.html
Chapter 3. Special Characters has where you can get a pid.
.
- Follow-Ups:
- Re: sort a file.
- From: Mr. X.
- Re: sort a file.
- References:
- sort a file.
- From: Mr. X.
- sort a file.
- Prev by Date: sort a file.
- Next by Date: Re: sort a file.
- Previous by thread: sort a file.
- Next by thread: Re: sort a file.
- Index(es):
Relevant Pages
|