Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

272
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!