ocehb: (Default)
ocehb ([personal profile] ocehb) wrote2006-07-13 01:31 pm
Entry tags:

И еще.

Имеется файл, каждая строка которого представляет собой запись из двух полей. Поля разделены табуляцией. Первое поле — время в time_t, второе поле — URL. Задача: для каждого встречающегося в файле URL выделить запись, которой соответствует самое раннее время.


на perl оно очевидно, а вот на shell:

sort -n file > file.out
while [ -s file.out ]; do
    head -1 file.out
    url=$(head -1 file.out | cut -f2)
    sed -i -e "\\|$url\$|d" file.out
done


результат:

# sort -n time.ip > time.ip.out
# while [[ -s time.ip.out ]]; do 
  head -1 time.ip.out
  url=$(head -1 time.ip.out | cut -f2)
  sed -i -e "\\|$url\$|d" time.ip.out
done
45      192.168.1.10
85      10.20.66.1
96      10.20.66.10
172     10.20.66.40
# ll time.ip.out
-rw-r--r--  1 ocheb ocehb 0 Jul 13 13:38 time.ip.out
#


Post a comment in response:

This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

If you are unable to use this captcha for any reason, please contact us by email at support@dreamwidth.org