The UNIX and Linux Forums  

Go Back   UNIX e Linux Forum > Inizio Forum > Shell scripting e di programmazione
.
google unix.com



Shell scripting e di programmazione Pubblica domande su KSH, CSH, SH, Bash, Perl, PHP, sed, awk e da altri script di shell e linguaggi di scripting shell qui.

Più di UNIX e Linux Forum Argomenti potreste trovare utili
Filo Thread Starter Forum Risposte Ultimo Post
Come ottenere il precedente mese di Korn Shell nvuradi Shell scripting e di programmazione 1 03-19-2008 12:31 AM
Come trovare il primo giorno del mese precedente in UNIX? Mohapatra Shell scripting e di programmazione 10 07-02-2007 09:57 PM
Specifica una data precedente, come data di inizio di script di shell ritzwan0 Shell scripting e di programmazione 2 09-25-2006 06:58 PM
Come arrivare mese precedente file savitha Shell scripting e di programmazione 7 03-23-2006 05:16 AM
il nome del file utilizzando mese precedente beilstwh Shell scripting e di programmazione 1 08-04-2004 05:21 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 02-25-2008
sirrtuan sirrtuan is offline
Utente Registrato
  
 

Iscriviti Data: febbraio 2008
Interventi: 18
Aiuto, ho bisogno di avere l'ultima data del mese precedente

Hi, I'm nuovo con Unix, Sto cercando di ottenere un ultimo giorno del mese precedente, con questo formato:% d% b% Y (esempio: 25 febbraio 2008).
Ecco quello che ho finora.

#! / bin / ksh
cur_month \u003d `date +% m`
cur_year \u003d `date +% Y`
PREV_MONTH \u003d$(($ cur_month-1))

# Check per vedere se questo è il gennaio
if [$ PREV_MONTH-lt 1]
allora
prev_year \u003d$(($ cur_year-1))
PREV_MONTH \u003d 12
LastDayOfMonth \u003d `/ bin / cal PREV_MONTH $ $ prev_year | grep-v" ^ $ "| tail -1 | awk '(print $ NF)'`
altro
LastDayOfMonth \u003d `/ bin / cal PREV_MONTH $ $ cur_year | grep-v" ^ $ "| tail -1 | awk '(print $ NF)'`
fi
\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u0
Sono in grado di ottenere l'ultimo giorno del mese precedente, ma non so come mettere indietro nel formato che volevo. Please help.

Grazie.
  #2 (permalink)  
Old 02-25-2008
Tytalus's Avatar
Tytalus Tytalus is offline Forum Advisor  
echo (1 .. 9) ^ 2 \; | bc
  
 

Iscriviti Data: giugno 2003
Localizzazione: Scozia
Interventi: 431
continua nello stile del vostro script di provare a utilizzare il codice simile al seguente:


Codice:
/bin/cal $prev_month $cur_year | grep -v "^$" | sed -n  '1p;$p' | tr "\n" " "  | awk '{print substr($1,1,3),$NF,$2}'

HTH
  #3 (permalink)  
Old 02-25-2008
sirrtuan sirrtuan is offline
Utente Registrato
  
 

Iscriviti Data: febbraio 2008
Interventi: 18
Tytalus,

Grazie per la rapida risposta, il codice che mi è un formato che mi serviva, ma mi ha dato del mese corrente. I ricerca di un ultimo giorno del mese precedente.
Si prega di consulenza.

Grazie.
  #4 (permalink)  
Old 02-25-2008
sirrtuan sirrtuan is offline
Utente Registrato
  
 

Iscriviti Data: febbraio 2008
Interventi: 18
I got it - dispiace

La ringrazio molto per il vostro aiuto.
  #5 (permalink)  
Old 02-25-2008
Tytalus's Avatar
Tytalus Tytalus is offline Forum Advisor  
echo (1 .. 9) ^ 2 \; | bc
  
 

Iscriviti Data: giugno 2003
Localizzazione: Scozia
Interventi: 431

Codice:
#  cat lastday.ksh
#!/bin/ksh
cur_month=`date +%m`
cur_year=`date +%Y`
prev_month=$(($cur_month-1))

# Check to see if this is January
if [ $prev_month -lt 1 ]
then
prev_year=$(($cur_year-1))
prev_month=12
LastDayOfMonth=`/bin/cal $prev_month $cur_year | grep -v "^$" | sed -n  '1p;$p' | tr "\n" " "  | awk '{print substr($1,1,3),$NF,$2}'`
else
LastDayOfMonth=`/bin/cal $prev_month $cur_year | grep -v "^$" | sed -n  '1p;$p' | tr "\n" " "  | awk '{print substr($1,1,3),$NF,$2}'`
fi
echo $LastDayOfMonth


#  ./lastday.ksh
Jan 31 2008


#  date
Mon Feb 25 16:23:48 GMT 2008

  #6 (permalink)  
Old 02-28-2008
sirrtuan sirrtuan is offline
Utente Registrato
  
 

Iscriviti Data: febbraio 2008
Interventi: 18
Un'altra domanda, come faccio a ottenere la prima di un mese precedente?
I'm not familia con sed.

Grazie.
  #7 (permalink)  
Old 02-28-2008
Tytalus's Avatar
Tytalus Tytalus is offline Forum Advisor  
echo (1 .. 9) ^ 2 \; | bc
  
 

Iscriviti Data: giugno 2003
Localizzazione: Scozia
Interventi: 431

Codice:
/bin/cal $month $year| grep -v "^$" | sed -n  '1p;3p' | tr "\n" " "  | awk '{print substr($1,1,3),$3,$2}'

In caso di lavoro ;-)
Closed Thread

Segnalibri

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 è 10:08 PM.


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