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
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:
match(s, r [, a])
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.