usando o awk para pegar dados da localização dinâmica

0

Eu compilei alguns códigos e tenho toneladas de erros, e quero criar uma tabela que mostrará algumas coisas: o caminho do arquivo de origem, o número da linha e a referência indefinida. O primeiro e o segundo não são muito problemáticos para escavar usando um simples awk e imprimir $ 1, $ 2 etc, mas a referência indefinida é problemática, já que aparece em diferentes lugares na saída.

Aqui, um trecho do log de erros que estou tentando analisar com um script que quero escrever.

out/target/product/gen/SHARED_LIBRARIES/libfishy_proto_intermediates/proto/base/fishy/fishy/prefix/fishy_proto/service_registry.pb.h:408: error: undefined reference to 'fishy_proto::Service::CopyFrom(fishy_proto::Service const&)'
base/fishy/fishy/impl/service.cpp:448: error: undefined reference to 'fishy_proto::Service::Service()'
base/fishy/fishy/impl/service.cpp:489: error: undefined reference to 'fishy_proto::Service::~Service()'
base/fishy/fishy/impl/service.cpp:489: error: undefined reference to 'fishy_proto::Service::~Service()'
base/fishy/fishy/impl/service_registry.cpp:51: error: undefined reference to 'fishy_proto::ServiceList::ServiceList()'
base/fishy/fishy/impl/service_registry.cpp:51: error: undefined reference to 'fishy_proto::ServiceList::~ServiceList()'
base/fishy/fishy/impl/service_registry.cpp:51: error: undefined reference to 'fishy_proto::ServiceList::~ServiceList()'
base/fishy/fishy/impl/service_registry.cpp:51: error: undefined reference to 'fishy_proto::ServiceList::~ServiceList()'
base/fishy/fishy/impl/service_registry.cpp:51: error: undefined reference to 'fishy_proto::ServiceList::~ServiceList()'
base/fishy/fishy/impl/service_registry.cpp:279: error: undefined reference to 'fishy_proto::Request::Request()'
base/fishy/fishy/impl/service_registry.cpp:319: error: undefined reference to 'fishy_proto::Request::~Request()'
base/fishy/fishy/impl/service_registry.cpp:319: error: undefined reference to 'fishy_proto::Request::~Request()'
base/fishy/fishy/impl/service_registry.cpp:722: error: undefined reference to 'fishy_proto::Request::Request()'
out/target/product/phaedra/gen/SHARED_LIBRARIES/libfishy_proto_intermediates/proto/base/fishy/fishy/prefix/fishy_proto/service_registry.pb.h:72: error: undefined reference to 'fishy_proto::Request_Type_descriptor()'
base/fishy/fishy/impl/service_registry.cpp:762: error: undefined reference to 'fishy_proto::Request::~Request()'
base/fishy/fishy/impl/service_registry.cpp:762: error: undefined reference to 'fishy_proto::Request::~Request()'
base/fishy/fishy/impl/service_registry.cpp:463: error: undefined reference to 'fishy_proto::Service::Service()'
base/fishy/fishy/impl/service_registry.cpp:500: error: undefined reference to 'fishy_proto::Service::~Service()'
base/fishy/fishy/impl/service_registry.cpp:500: error: undefined reference to 'fishy_proto::Service::~Service()'
external/protobuf/src/google/protobuf/arena.h:649: error: undefined reference to 'fishy_proto::ServiceGroup::ServiceGroup()'
external/protobuf/src/google/protobuf/arena.h:309: error: undefined reference to 'fishy_proto::ServiceGroup::ServiceGroup()'
external/protobuf/src/google/protobuf/arena.h:649: error: undefined reference to 'fishy_proto::Service::Service()'
external/protobuf/src/google/protobuf/arena.h:309: error: undefined reference to 'fishy_proto::Service::Service()'

Como você pode ver, as linhas 1 e 14 mostram a referência indefinida em lugar diferente das outras linhas.

Existe uma maneira de executar um awk que ignore a localização exata, mas ainda traga o valor para a referência indefinida?

    
por Hetz Ben Hamo 20.02.2018 / 12:32

4 respostas

1

Sua saída de amostra indica que a "referência indefinida" sempre será o campo final awk de uma linha. Em awk , NF será o número de campos e $NF será o campo cujo número é "o número de campos", ou seja. o campo final, que é o que você está pedindo.

awk '{print "undefined reference = " $NF}'
    
por 20.02.2018 / 12:46
1

the path of the source file, line number, and the undefined reference to

sed solução:

sed -E 's/^([^:]+):([0-9]+): error: undefined reference to (.*)/  /' file

A saída:

out/target/product/gen/SHARED_LIBRARIES/libfishy_proto_intermediates/proto/base/fishy/fishy/prefix/fishy_proto/service_registry.pb.h 408 'fishy_proto::Service::CopyFrom(fishy_proto::Service const&)'
base/fishy/fishy/impl/service.cpp 448 'fishy_proto::Service::Service()'
base/fishy/fishy/impl/service.cpp 489 'fishy_proto::Service::~Service()'
base/fishy/fishy/impl/service.cpp 489 'fishy_proto::Service::~Service()'
base/fishy/fishy/impl/service_registry.cpp 51 'fishy_proto::ServiceList::ServiceList()'
base/fishy/fishy/impl/service_registry.cpp 51 'fishy_proto::ServiceList::~ServiceList()'
base/fishy/fishy/impl/service_registry.cpp 51 'fishy_proto::ServiceList::~ServiceList()'
base/fishy/fishy/impl/service_registry.cpp 51 'fishy_proto::ServiceList::~ServiceList()'
base/fishy/fishy/impl/service_registry.cpp 51 'fishy_proto::ServiceList::~ServiceList()'
base/fishy/fishy/impl/service_registry.cpp 279 'fishy_proto::Request::Request()'
base/fishy/fishy/impl/service_registry.cpp 319 'fishy_proto::Request::~Request()'
base/fishy/fishy/impl/service_registry.cpp 319 'fishy_proto::Request::~Request()'
base/fishy/fishy/impl/service_registry.cpp 722 'fishy_proto::Request::Request()'
out/target/product/phaedra/gen/SHARED_LIBRARIES/libfishy_proto_intermediates/proto/base/fishy/fishy/prefix/fishy_proto/service_registry.pb.h 72 'fishy_proto::Request_Type_descriptor()'
base/fishy/fishy/impl/service_registry.cpp 762 'fishy_proto::Request::~Request()'
base/fishy/fishy/impl/service_registry.cpp 762 'fishy_proto::Request::~Request()'
base/fishy/fishy/impl/service_registry.cpp 463 'fishy_proto::Service::Service()'
base/fishy/fishy/impl/service_registry.cpp 500 'fishy_proto::Service::~Service()'
base/fishy/fishy/impl/service_registry.cpp 500 'fishy_proto::Service::~Service()'
external/protobuf/src/google/protobuf/arena.h 649 'fishy_proto::ServiceGroup::ServiceGroup()'
external/protobuf/src/google/protobuf/arena.h 309 'fishy_proto::ServiceGroup::ServiceGroup()'
external/protobuf/src/google/protobuf/arena.h 649 'fishy_proto::Service::Service()'
external/protobuf/src/google/protobuf/arena.h 309 'fishy_proto::Service::Service()'
    
por 20.02.2018 / 12:59
0

Se você não se importa em usar o perl:

perl -pe 's/^(.*?):(\d+): error: undefined reference to (.*)/\t\t/g'

A saída do seu exemplo ficaria assim:

out/target/product/gen/SHARED_LIBRARIES/libfishy_proto_intermediates/proto/base/fishy/fishy/prefix/fishy_proto/service_registry.pb.h    408 'fishy_proto::Service::CopyFrom(fishy_proto::Service const&)'
base/fishy/fishy/impl/service.cpp   448 'fishy_proto::Service::Service()'
base/fishy/fishy/impl/service.cpp   489 'fishy_proto::Service::~Service()'
base/fishy/fishy/impl/service.cpp   489 'fishy_proto::Service::~Service()'
base/fishy/fishy/impl/service_registry.cpp  51  'fishy_proto::ServiceList::ServiceList()'
base/fishy/fishy/impl/service_registry.cpp  51  'fishy_proto::ServiceList::~ServiceList()'
base/fishy/fishy/impl/service_registry.cpp  51  'fishy_proto::ServiceList::~ServiceList()'
base/fishy/fishy/impl/service_registry.cpp  51  'fishy_proto::ServiceList::~ServiceList()'
base/fishy/fishy/impl/service_registry.cpp  51  'fishy_proto::ServiceList::~ServiceList()'
base/fishy/fishy/impl/service_registry.cpp  279 'fishy_proto::Request::Request()'
base/fishy/fishy/impl/service_registry.cpp  319 'fishy_proto::Request::~Request()'
base/fishy/fishy/impl/service_registry.cpp  319 'fishy_proto::Request::~Request()'
base/fishy/fishy/impl/service_registry.cpp  722 'fishy_proto::Request::Request()'
out/target/product/phaedra/gen/SHARED_LIBRARIES/libfishy_proto_intermediates/proto/base/fishy/fishy/prefix/fishy_proto/service_registry.pb.h    72  'fishy_proto::Request_Type_descriptor()'
base/fishy/fishy/impl/service_registry.cpp  762 'fishy_proto::Request::~Request()'
base/fishy/fishy/impl/service_registry.cpp  762 'fishy_proto::Request::~Request()'
base/fishy/fishy/impl/service_registry.cpp  463 'fishy_proto::Service::Service()'
base/fishy/fishy/impl/service_registry.cpp  500 'fishy_proto::Service::~Service()'
base/fishy/fishy/impl/service_registry.cpp  500 'fishy_proto::Service::~Service()'
external/protobuf/src/google/protobuf/arena.h   649 'fishy_proto::ServiceGroup::ServiceGroup()'
external/protobuf/src/google/protobuf/arena.h   309 'fishy_proto::ServiceGroup::ServiceGroup()'
external/protobuf/src/google/protobuf/arena.h   649 'fishy_proto::Service::Service()'
external/protobuf/src/google/protobuf/arena.h   309 'fishy_proto::Service::Service()'
    
por 20.02.2018 / 13:02
0

Eu fiz pelo método abaixo usando sed

sed -ne "s/\(.*error:\)\(.*reference to \)\('.*'\)//p" inputfile

Saída

out/target/product/gen/SHARED_LIBRARIES/libfishy_proto_intermediates/proto/base/fishy/fishy/prefix/fishy_proto/service_registry.pb.h:408: error:'fishy_proto::Service::CopyFrom(fishy_proto::Service const&)'
base/fishy/fishy/impl/service.cpp:448: error:'fishy_proto::Service::Service()'
base/fishy/fishy/impl/service.cpp:489: error:'fishy_proto::Service::~Service()'
base/fishy/fishy/impl/service.cpp:489: error:'fishy_proto::Service::~Service()'
base/fishy/fishy/impl/service_registry.cpp:51: error:'fishy_proto::ServiceList::ServiceList()'
base/fishy/fishy/impl/service_registry.cpp:51: error:'fishy_proto::ServiceList::~ServiceList()'
base/fishy/fishy/impl/service_registry.cpp:51: error:'fishy_proto::ServiceList::~ServiceList()'
base/fishy/fishy/impl/service_registry.cpp:51: error:'fishy_proto::ServiceList::~ServiceList()'
base/fishy/fishy/impl/service_registry.cpp:51: error:'fishy_proto::ServiceList::~ServiceList()'
base/fishy/fishy/impl/service_registry.cpp:279: error:'fishy_proto::Request::Request()'
base/fishy/fishy/impl/service_registry.cpp:319: error:'fishy_proto::Request::~Request()'
base/fishy/fishy/impl/service_registry.cpp:319: error:'fishy_proto::Request::~Request()'
base/fishy/fishy/impl/service_registry.cpp:722: error:'fishy_proto::Request::Request()'
out/target/product/phaedra/gen/SHARED_LIBRARIES/libfishy_proto_intermediates/proto/base/fishy/fishy/prefix/fishy_proto/service_registry.pb.h:72: error:'fishy_proto::Request_Type_descriptor()'
base/fishy/fishy/impl/service_registry.cpp:762: error:'fishy_proto::Request::~Request()'
base/fishy/fishy/impl/service_registry.cpp:762: error:'fishy_proto::Request::~Request()'
base/fishy/fishy/impl/service_registry.cpp:463: error:'fishy_proto::Service::Service()'
base/fishy/fishy/impl/service_registry.cpp:500: error:'fishy_proto::Service::~Service()'
base/fishy/fishy/impl/service_registry.cpp:500: error:'fishy_proto::Service::~Service()'
external/protobuf/src/google/protobuf/arena.h:649: error:'fishy_proto::ServiceGroup::ServiceGroup()'
external/protobuf/src/google/protobuf/arena.h:309: error:'fishy_proto::ServiceGroup::ServiceGroup()'
external/protobuf/src/google/protobuf/arena.h:649: error:'fishy_proto::Service::Service()'
external/protobuf/src/google/protobuf/arena.h:309: error:'fishy_proto::Service::Service()'
    
por 20.02.2018 / 16:11