И еще.

Jul. 13th, 2006 01:31 pm
ocehb: (Default)
[personal profile] ocehb
Имеется файл, каждая строка которого представляет собой запись из двух полей. Поля разделены табуляцией. Первое поле — время в 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
#

Date: 2006-07-28 02:21 pm (UTC)
From: [identity profile] ex-svpv.livejournal.com
sort -t$'\t' -k1n |sort -t$'\t' -u -k2

Profile

ocehb: (Default)
ocehb

January 2021

S M T W T F S
     12
345 6789
10111213141516
17181920212223
24252627282930
31      

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Feb. 5th, 2026 03:44 pm
Powered by Dreamwidth Studios