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
cat file1 leggere riga per riga quindi grep-A 15 righe in fileb irongeekio Shell scripting e di programmazione 6 01-28-2009 06:30 AM
Unire le linee in ordine inverso. aggiungere la linea 1 alla linea 2. dwalley Shell scripting e di programmazione 7 08-04-2008 08:11 AM
Aggiungendo il numero della linea per ogni linea e ottenere il numero totale di linee chiru_h Shell scripting e di programmazione 2 03-25-2008 10:19 AM
2 linee per fare in 1 linea utilizzando awk cdfd123 Shell scripting e di programmazione 2 10-03-2007 08:44 PM
Aggiungendo linea / linee con sed nir_s Shell scripting e di programmazione 28 07-24-2005 03:36 AM

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 04-22-2009
pinnacle pinnacle is offline
Utente Registrato
  
 

Iscriviti Data: aprile 2009
Interventi: 182
Awk 2 linee a 1 linea

File di input:

Citazione:
Ingresso:
host1 server1
database1 5
host2 server2
database2 5
host3 server3
database3 5
Richiesto Risultato:
Citazione:
host1 server1 database1 5
host2 server2 database2 5
host3 server3 database3 5
Ho cercato il seguente codice:

Codice:
nawk '{for(i=1; i<=NR; i+2) {print NR,$0; getline ;print \n $0; NR=NR+2}}' temp

Ma doesnt fornisce il risultato corretto.
L'aiuto è apprezzato
  #2 (permalink)  
Old 04-22-2009
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderatore
  
 

Iscriviti Data: febbraio 2005
Località: Boston, MA
Messaggi: 5.131

Codice:
paste -d' ' - - < temp
OR
nawk 'ORS=(FNR%2)?FS:RS' temp

  #3 (permalink)  
Old 04-22-2009
pinnacle pinnacle is offline
Utente Registrato
  
 

Iscriviti Data: aprile 2009
Interventi: 182
Citazione:
Originalmente inviato da vgersh99 View Post
Codice:
paste -d' ' - - < temp
OR
nawk 'ORS=(FNR%2)?FS:RS' temp
Grazie pro


Codice:
paste -d' ' - - < temp
nawk 'ORS=(FNR%2)?FS:RS' temp

Gradirei se è possibile spiegare questo.
  #4 (permalink)  
Old 04-22-2009
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderatore
  
 

Iscriviti Data: febbraio 2005
Località: Boston, MA
Messaggi: 5.131
Citazione:
Originalmente inviato da zenith View Post
Grazie pro


Codice:
paste -d' ' - - < temp
nawk 'ORS=(FNR%2)?FS:RS' temp

Gradirei se è possibile spiegare questo.
È possibile leggere le pagine man di 'incollare' per darvi un alto livello di ciò che fa - il resto dovrebbe essere facile.
awk:

Codice:
(FNR%2) - get a 'modulo' of the current file RecordNumber (FNR) over 2 - every OTHER line.
If the mod is NON-zero, return 'FS' (FieldSeparator)
If the mod is zero, return RecordSeparator (RS)
ORS= - assign the returned value to the OutputRecordSeparator (ORS)

In other words...
If we're dealing with the ODD record/line numbers (1,3,5,7 etc), print the line and FS (separate the next line)
If we're dealing with the EVEN record/line numbers (2.4.6.8 etc), print the line and the ORS (which is by default is newLine).

  #5 (permalink)  
Old 04-22-2009
pinnacle pinnacle is offline
Utente Registrato
  
 

Iscriviti Data: aprile 2009
Interventi: 182
Citazione:
Originalmente inviato da vgersh99 View Post
È possibile leggere le pagine man di 'incollare' per darvi un alto livello di ciò che fa - il resto dovrebbe essere facile.
awk:

Codice:
(FNR%2) - get a 'modulo' of the current file RecordNumber (FNR) over 2 - every OTHER line.
If the mod is NON-zero, return 'FS' (FieldSeparator)
If the mod is zero, return RecordSeparator (RS)
ORS= - assign the returned value to the OutputRecordSeparator (ORS)
 
In other words...
If we're dealing with the ODD record/line numbers (1,3,5,7 etc), print the line and FS (separate the next line)
If we're dealing with the EVEN record/line numbers (2.4.6.8 etc), print the line and the ORS (which is by default is newLine).
Grazie Signore,

Minori cambiamento; necessità di uscita separati da virgole.

Ho provato, ma ha errore di sintassi.


Codice:
nawk '{ORS=(FNR%2)?FS:RS}; OFS=,' temp

Apprezziamo il tuo aiuto
  #6 (permalink)  
Old 04-22-2009
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderatore
  
 

Iscriviti Data: febbraio 2005
Località: Boston, MA
Messaggi: 5.131

Codice:
nawk -F, 'ORS=(FNR%2)?FS:RS' temp

  #7 (permalink)  
Old 04-22-2009
pinnacle pinnacle is offline
Utente Registrato
  
 

Iscriviti Data: aprile 2009
Interventi: 182
Awk con strani spazi (uscita dal server Sybase)

Citazione:
Originalmente inviato da vgersh99 View Post
Codice:
nawk -F, 'ORS=(FNR%2)?FS:RS' temp
Quando i file di input incollato sul sito web. Ho qualche strano spazi, ma quando ho incollato i think sito rimosso. quindi mi è connessi.


Risultato Requried
host1, server1, database1, 5
host2, server2, database2, 5
host3, server3, database3, 5

I risultati sono sempre è anche allegata

Appreciate aiutare
Attached Files
File Type: txt inputfile.txt (375 Byte, 21 opinioni)
File Type: txt output_i_am_getting.txt (363 Bytes, 19 views)
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 è 09:37 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