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
Como pode depurar nossos UNIX shell script? psiva_arul UNIX & avançada para usuários experientes 3 09-07-2008 11:31
Como depurar o script awk chella Programação Shell Script e 2 11-08-2007 07:51
debug AIX 4.3 itik AIX 2 10-29-2007 11:56
o modo de depuração ramneek Alto Nível de programação 1 09-19-2005 07:35
espaço em disco script depurar - postado antes bryan Programação Shell Script e 3 04-28-2005 08:50

 
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 10-01-2007
mboro mboro is offline
Usuário
  
 

Join Date: Oct 2007
Posts: 2
Talking Depurar um Awk Script

Gostaria de extrair os seguintes campos do arquivo texto anexado. Copiei o conteúdo de um arquivo pdf e colou-os no arquivo de texto para que eu possa usar awk para extraí-los. O layout é conforme listado abaixo.

name1, NAME2, name3, name4, o título, designação, nacionalidade, data de nascimento,
nacional identificação, endereço, enumerados On, Outras informações


O problema é que se eu remover os comentários no script parece-me chegar a colocar nada no arquivo. Por favor ajudem estou de novo a sua programação e awk enlouquecedor mim. E algumas das informações que eu estou na extracção é errado colunas. O que estou fazendo errado? Favor consultar um especialista. Eu sou novo a este idioma

1) Este é o script


Código:
  BEGIN { print "name1,name2,name3,name4,Title,designation,nationality,dob,national identication,address,listed On,Other information";Title=""; dob=""; nationality="";
  }
/*Name(:?)/ {

    if (Title != "" )
    {
      printf ",%s",Title;
      Title=" ";
    }
    if (designation != "" )
    {
      printf ",%s",designation;
      designation=" ";
    }
    if (nationality != "" )
    {
      printf ",%s",nationality;
      nationality=" ";
    }
    if (dob != "" )
    {
      printf ",%s\n",dob;
      dob=" ";
    }
    line = $0;
    gsub(/[[:digit:]]+:/,"",line);
    gsub(/[[:digit:]]+\./,"",line);
    sub(/*Name:/,"",line);
    sub(/*Name/,"",line);
    split(line,names);
    x = 1;
    while (x<=3)
    {
      printf "%s,", names[x];
      x++;
    }
    printf "%s", names[x];
    name1 = $4;
    name2 = $6;
    name3=$8;
    name4=$10;
}
##--> Add title field
/Title:/ {
  line=$0;
  idx1 = index(line,"Title:");
  idx2 = index(line,"Designation:");
  if (idx2==0)
  {
    idx2 = length(line)+1;
  }
  Title = substr(line, idx1+length("Title:"), idx2 - idx1 - length("Title:") );
  sub(",",";",Title)
}

##--> Add Designation
/Designation:/ {
  line=$0;
  idx1 = index(line,"Designation:");
  idx2 = index(line,"DOB:");
  if (idx2==0)
  {
    idx2 = length(line)+1;
  }
  designation = substr(line, idx1+length("Designation:"), idx2 - idx1 - length("Designation:") );
  sub(",",";",designation)
}

/*Nationality: / {
  line = $0;
  idx1 = index(line,"*Nationality: ");
  idx2 = index(line,"Passport");
  nationality = substr(line, idx1+length("*Nationality: "), idx2 - idx1 - length("*Nationality: ") );
  sub(",",";",nationality)
}
/DOB:/ {
  line=$0;
  idx1 = index(line,"DOB:");
  idx2 = index(line,"POB");
  if (idx2==0)
  {
    idx2 = length(line)+1;
  }
  dob = substr(line, idx1+length("DOB:"), idx2 - idx1 - length("DOB:") );
  sub(",",";",dob)
}
##/National identification no.:/ {
  ##line=$0;
  ##idx1 = index(line,"National identification no.:");
  ##idx2 = index(line,"Address");
  ##if (idx2==0)
  ##{
  ##  idx2 = length(line)+1;
  ##}
  ##dob = substr(line, idx1+length("National identification no.:"), idx2 - idx1 - length("National identification no.:") );
  ##sub(",",";",National identification no)
##}

##/Title:/ {context="title"; printf "%s:",context}

Attached Files
File Type: zip AwkScripts.zip (2,4 KB, 10 views)

Última edição por vino; em 10/01/2007 07:08.. Motivo: Adicionado código tags.
 

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 01:05.


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