Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.debian.user > #170614
| From | Rodolfo Medina <rodolfo.medina@gmail.com> |
|---|---|
| Newsgroups | linux.debian.user |
| Subject | Re: Indexing Unix command |
| Date | 2016-08-01 16:20 +0200 |
| Message-ID | <s1met-7pd-5@gated-at.bofh.it> (permalink) |
| References | <s1kZ3-6qC-17@gated-at.bofh.it> <s1l8J-6J6-1@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
Christian Seiler <christian@iwakd.de> writes:
> On 08/01/2016 02:52 PM, Rodolfo Medina wrote:
>> with the following simple script:
>>
>> #!/bin/sh
>>
>> cat index.idx | sort > index.ind
>>
>> I sort the contents of a file and write it in another file. Now, I want
>> that a small vertical space, i.e. an empty line or two, were inserted before
>> all the words that start with a new letter.
>
> If the first letters of your words are only ASCII characters
> (or you are using an 8 bit character encoding), then the
> following should do the trick:
>
> sort < index.idx | awk 'BEGIN {
> c = -1;
> }
> {
> if (substr($0, 1, 1) != c && c != -1)
> printf("\n\n");
> c = substr($0, 1, 1);
> print;
> }' > index.ind
>
> See also:
> https://en.wikibooks.org/wiki/AWK
Thanks indeed, it works fine.
Rodolfo
Back to linux.debian.user | Previous | Next — Previous in thread | Find similar | Unroll thread
Indexing Unix command Rodolfo Medina <rodolfo.medina@gmail.com> - 2016-08-01 15:00 +0200
Re: Indexing Unix command Christian Seiler <christian@iwakd.de> - 2016-08-01 15:10 +0200
Re: Indexing Unix command Rodolfo Medina <rodolfo.medina@gmail.com> - 2016-08-01 16:20 +0200
csiph-web