Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

275
Visualizações
AWK match working locally but not in bash on debian server

I have following strange issue. I'll try to extract a string from a textfile with awk, but it's not working on the bash at my server.

Textfile looks like (textfile.txt)

dummy text name="formtoken" value="bd54839c3348d1c6ed7ab2c266f8a50b" dummy text

And I want to fetch the formtoken value out of the file. My awk statement is:

awk '/formtoken/ {match($0,/name="formtoken" value="(.{32})"/,arr); print arr[1]}' < textfile.txt

Locally the commands result is "bd54839c3348d1c6ed7ab2c266f8a50b"

On the debian server (connected via ssh) I get "awk: line 1: syntax error at or near ,"

Maybe someone has a good hint for me :)

Thanks,

RCX

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Debian-based distributions use Mawk as the default awk, and your command doesn't work with Mawk.

It works with Gawk (GNU Awk), which is probably what you've installed locally.

The reason your command doesn't work with Mawk is that you're using the 3-parameter form of the match() function, which is Gawk extension; the function signatures are:

  • Gawk: match(s, r [, a])
  • Mawk (and BSD Awk, and POSIX): match(s, r)

Ed Morton, in a since cleaned-up comment, suggests using the following variation of the command, which should work with all Awks:

awk 'sub(/.*name="formtoken" value="/,""){ sub(/".*/,""); print}' textfile.txt
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda