The UNIX and Linux Forums  

Go Back   O UNIX e Linux Forum > Top Fóruns > Programação Shell Script e
.
google unix.com



Programação Shell Script e Post perguntas sobre ksh, CSH, SH, BASH, Perl, PHP, SED, Awk e outros scripts shell e shell scripts línguas aqui.

Mais UNIX e Linux Fórum Tópicos Você pode achar Helpfull
Fio Thread Starter Fórum Respostas Última postagem
gato ficheiro1 ler linha por linha, então grep-A 15 linhas no fileb irongeekio Programação Shell Script e 6 01-28-2009 06:30
Unir linhas em sentido inverso. append linha 1 para linha 2. dwalley Programação Shell Script e 7 08-04-2008 08:11
Anexando linha número para cada linha e cada vez número total de linhas chiru_h Programação Shell Script e 2 03-25-2008 10:19
para fazer 2 linhas em 1 linha usando awk cdfd123 Programação Shell Script e 2 10-03-2007 08:44
Anexando linha / linhas com sed nir_s Programação Shell Script e 28 07-24-2005 03:36

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 Pesquisar este Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-22-2009
pinnacle pinnacle is offline
Usuário
  
 

Join Date: Apr 2009
Lugares: 182
Awk 2 linhas para 1 linha

Input File:

Citação:
Entrada:
host1 servidor1
database1 5
host2 server2
database2 5
host3 SERVER3
database3 5
Requerido Resultado:
Citação:
host1 servidor1 database1 5
host2 server2 database2 5
host3 SERVER3 database3 5
Eu testei o seguinte código:
Código:
nawk '{for(i=1; i<=NR; i+2) {print NR,$0; getline ;print \n $0; NR=NR+2}}' temp
Doesnt Mas dá o resultado correto.
Ajuda é apreciada
  #2 (permalink)  
Old 04-22-2009
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderador
  
 

Join Date: Feb 2005
Localização: Boston, MA
Mensagens: 5.122
Código:
paste -d' ' - - < temp
OR
nawk 'ORS=(FNR%2)?FS:RS' temp
  #3 (permalink)  
Old 04-22-2009
pinnacle pinnacle is offline
Usuário
  
 

Join Date: Apr 2009
Lugares: 182
Citação:
Originally Posted by vgersh99 View Post
Código:
paste -d' ' - - < temp
OR
nawk 'ORS=(FNR%2)?FS:RS' temp
Obrigado pro

Código:
paste -d' ' - - < temp
nawk 'ORS=(FNR%2)?FS:RS' temp
Gostaria de saber se pode explicar isso.
  #4 (permalink)  
Old 04-22-2009
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderador
  
 

Join Date: Feb 2005
Localização: Boston, MA
Mensagens: 5.122
Citação:
Originally Posted by zenith View Post
Obrigado pro

Código:
paste -d' ' - - < temp
nawk 'ORS=(FNR%2)?FS:RS' temp
Gostaria de saber se pode explicar isso.
Você pode ler as páginas man para 'colar' a dar-lhe um alto nível do que faz - o resto deve ser fácil.
awk:
Código:
(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
Usuário
  
 

Join Date: Apr 2009
Lugares: 182
Citação:
Originally Posted by vgersh99 View Post
Você pode ler as páginas man para 'colar' a dar-lhe um alto nível do que faz - o resto deve ser fácil.
awk:
Código:
(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).
Obrigado Senhor,

Pequenas mudanças; necessidade de saída separados por vírgulas.

Eu testei este, mas tem erro de sintaxe.

Código:
nawk '{ORS=(FNR%2)?FS:RS}; OFS=,' temp
Appreciate your help
  #6 (permalink)  
Old 04-22-2009
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderador
  
 

Join Date: Feb 2005
Localização: Boston, MA
Mensagens: 5.122
Código:
nawk -F, 'ORS=(FNR%2)?FS:RS' temp
  #7 (permalink)  
Old 04-22-2009
pinnacle pinnacle is offline
Usuário
  
 

Join Date: Apr 2009
Lugares: 182
Awk estranho com espaços (saída de sybase servidor)

Citação:
Originally Posted by vgersh99 View Post
Código:
nawk -F, 'ORS=(FNR%2)?FS:RS' temp
Quando colado arquivo de entrada no site. Eu tenho alguns espaços estranho, mas quando eu penso colado site é removido. Por isso estou a montar.


Exigidas Resultado
host1, servidor1, database1, 5
host2, server2, database2, 5
host3, SERVER3, database3, 5

Resultado Estou recebendo também é anexada

Appreciate ajudar
Attached Files
File Type: txt inputfile.txt (375 Bytes, 21 visualizações)
File Type: txt output_i_am_getting.txt (363 Bytes, 19 views)
Closed Thread

Marcadores

Thread Tools Pesquisar este Thread
Pesquisar este Thread:

Pesquisa Avançada
Display Modes Esta taxa Thread
Esta taxa Thread:

Destacamento Regimento
Você não pode postar novas threads
Você não pode postar respostas
Você não pode postar anexos
Você não pode editar suas postagens

BB code é Ligado
Smilies são Ligado
[IMG] código é Ligado
Código HTML é Desligado
Trackbacks são Ligado
Pingbacks são Ligado
Refbacks são Ligado




Todos os horários são GMT -4. A hora é agora 12:21.


Powered by: vBulletinCopyright © 2000 - 2006, Jelsoft Enterprises Limited. Língua Traduções Powered by .
vBCredits v1.4 Copyright © 2007 - 2008, PixelFX Studios
O UNIX e Linux Fóruns Content Copyright © 1993-2009. Todos os Direitos Reserved.Ad Gestão por RedTyger

Content Relevant URLs por vBSEO 3.2.0