The UNIX and Linux Forums  
Ciao e benvenuto da parte degli Stati Uniti al UNIX e Linux Forum! Grazie per la visita ed unirsi alla nostra Comunità Globale.

Go Back   UNIX e Linux Forum > Inizio Forum > UNIX e avanzata per utenti esperti
.
google unix.com



UNIX e avanzata per utenti esperti Expert-to-Expert. Ulteriori avanzata UNIX, comandi UNIX, Linux, Sistemi Operativi, System Administration, Programmazione, Shell, Shell Script, Solaris, Linux, HP-UX, AIX, OS X, BSD.

Più di UNIX e Linux Forum Argomenti potreste trovare utili
Filo Thread Starter Forum Risposte Ultimo Post
Semplice domanda (per voi ragazzi, difficile per me) BkontheShell718 Shell scripting e di programmazione 3 01-07-2008 11:48 AM
[domanda] duro esercizio, help needed EnioMarques UNIX for Dummies Domande & Risposte 2 09-20-2007 10:22 PM
Hard Drive Domanda Netghost AIX 0 08-24-2006 01:01 PM
Please Help .... Disperato bisogno! Domanda difficile! Sparticus007 UNIX e avanzata per utenti esperti 1 01-11-2002 06:43 PM
Solo esperti! Hard Domanda Ahead! Foo49272 UNIX e avanzata per utenti esperti 1 01-07-2002 10:22 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Cerca in questo Thread Rate Thread Modalità di visualizzazione
  #1 (permalink)  
Old 08-01-2008
msb65 msb65 is offline
Utente Registrato
  
 

Join Date: Aug 2008
Interventi: 89
domanda difficile

Ho una directory che contiene una serie di file di formato:
A2008001231000.L2

Ho solo la cura circa 6-8 cifre, in modo che i file sono effettivamente:
?????---*. L2

Ho file che variano da 001 *. ????? ????? L2 a 366 *. L2

Va notato questi tre cifre rappresentano il giorno giuliana dei file. Il mio obiettivo è quello di essere in grado di definire due variabili: start_day e end_day. Come faccio fuori elenco di tutti i file tra start_day e end_day. NOTA: Poiché la giuliana giorni deve essere di 3 cifre, che complica le questioni.
  #2 (permalink)  
Old 08-02-2008
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Ubicazione: Ashburn, Virginia
Messaggi: 9.115
Se si pensa che questo sia difficile, è necessario utilizzare la lingua sbagliata. Qui è in ksh. Quello che chiamiamo "giuliana" Mi chiamano "giorno di anni". Look up "giuliana giorno" su wikipedia. Questo script utilizza il mio datecalc script per permettere all'utente di inserire gli estremi come aaaammgg. datecalc è inviato a questo sito e la nostra funzione di ricerca può trovare per voi.

Una cosa su ksh ... un numero con uno zero iniziale è stimato in ottale. Questo è il motivo per cui tengo stripping largo numero di zeri iniziali prima di fare l'aritmetica.

Codice:
$ ls -1 files
A2008001231000.L2
A2008021231000.L2
A2008041231000.L2
A2008061231000.L2
A2008081231000.L2
A2008101231000.L2
$
$
$
$ ./findit
enter start yyyymmdd - 20080101
enter end yyyymmdd - 20080220
A2008001231000.L2 is in range
A2008021231000.L2 is in range
A2008041231000.L2 is in range
$
$
$
$ cat findit
#! /usr/bin/ksh

read start?"enter start yyyymmdd - "
y1=${start%????}
d1=${start#??????}
temp=${start%$d1}
m1=${temp#$y1}
m1=${m1#0}
d1=${d1#0}
doy1=$(($(datecalc -a $y1 $m1 $d1 - $y1 1 1) + 1))
#echo $start $y1 $m1 $d1 $doy1

read end?"enter end yyyymmdd - "
y2=${end%????}
d2=${end#??????}
temp=${end%$d2}
m2=${temp#$y2}
m2=${m2#0}
d2=${d2#0}
doy2=$(($(datecalc -a $y2 $m2 $d2 - $y2 1 1) + 1))
#echo $start $y2 $m2 $d2 $doy2

cd files
ls | while read name ; do
        temp=${name#?}
        temp1=${temp#????}
        f_year=${temp%$temp1}
        temp2=${temp1#???}
        f_doy=${temp1%$temp2}
        f_doy=${f_doy##*(0)}
#       echo $name $f_year $f_doy
        if ((y1<=f_year && doy1<=f_doy && f_year<=y2 && f_doy<=doy2)) ; then
                echo $name is in range
        fi
done
exit 0
$
  #3 (permalink)  
Old 08-02-2008
redoubtable redoubtable is offline
Utente Registrato
  
 

Join Date: Aug 2008
Posizione: Portogallo
Interventi: 242
Vedo che sei in mktime () paradiso.
Da uomo mktime:
Codice:
           struct tm {
               int tm_sec;         /* seconds */
               int tm_min;         /* minutes */
               int tm_hour;        /* hours */
               int tm_mday;        /* day of the month */
               int tm_mon;         /* month */
               int tm_year;        /* year */
               int tm_wday;        /* day of the week */
               int tm_yday;        /* day in the year */
               int tm_isdst;       /* daylight saving time */
           };

 tm_yday
              The number of days since January 1, in the range 0 to 365.
Beh, non ho potuto ottenere mktime () di lavorare direttamente, ma ho ancora usato tm_yday.
Codice:
Tsunami julian_days # perl test2.pl 
Enter start date [yyyy/mm/dd]: 20080101
Enter end date [yyyy/mm/dd]: 20080220
A2008041231000.L2
A2008021231000.L2
A2008001231000.L2
Tsunami julian_days # perl test2.pl 
Enter start date [yyyy/mm/dd]: 2008/01/01  
Enter end date [yyyy/mm/dd]: 2008/02/20
A2008041231000.L2
A2008021231000.L2
A2008001231000.L2
Tsunami julian_days #
e il codice:

Codice:
#!/usr/bin/perl -w

use POSIX;

$| = 1;

my $input;
my (@date_s, @date_e);

opendir(DIR, ".") || die "can't opendir: $!";
@dots = grep { ! /^\./ && /\.L2$/ } readdir(DIR);
closedir DIR;

print "Enter start date [yyyy/mm/dd]: ";
($input = <STDIN>) =~ /(\d{4})\/*-*(\d{2})\/*-*(\d{2})/;
$date_s[0] = mktime (0, 0, 0, $3, ($2-1), ($1-1900), 0, 0);
$date_s[2] = $1;
print "Enter end date [yyyy/mm/dd]: ";
($input = <STDIN>) =~ /(\d{4})\/*-*(\d{2})\/*-*(\d{2})/;
$date_e[0] = mktime (0, 0, 0, $3, ($2-1), ($1-1900), 0, 0);
$date_e[2] = $1;
(undef, undef, undef, undef, undef, undef, undef, $date_s[1] ,undef) = localtime($date_s[0]);
(undef, undef, undef, undef, undef, undef, undef, $date_e[1] ,undef) = localtime($date_e[0]);

foreach my $i (@dots)
{
        $i =~ /^A(\d{4})(\d{3})/;
        print $i . "\n" if (($1 >= $date_s[2] && $1 <= $date_e[2]) && (($2+0) >= $date_s[1] && ($2+0) <= $date_e[1]));  
}
Closed Thread

Segnalibri

Tag
datecalc

Thread Tools Cerca in questo Thread
Cerca in questo Thread:

Ricerca Avanzata
Modalità di visualizzazione Vota questo thread
Vota questo thread:

Distacco regolamento
Tu non può post nuovo thread
Tu non può inviare una risposta
Tu non può postare allegati
Tu non può modificare i tuoi post

BB codice è Su
Smilies sono Su
[IMG] codice Su
Codice HTML è Chiuso
Trackbacks sono Su
Pingbacks sono Su
Refbacks sono Su




Tutti gli orari sono GMT -4. La data di oggi è 08:30 AM.


Powered by: vBulletin, Copyright © 2000 - 2006, Jelsoft Enterprises Limited. Traduzioni Powered by .
vBCredits v1.4 Copyright © 2007 - 2008, PixelFX Studios
UNIX e Linux Forum Content Copyright © 1993-2009. Tutti i diritti Reserved.Ad di gestione da RedTyger

Contenuti pertinenti URL da vBSEO 3.2.0