LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-04-2018, 08:58 AM   #1
rbees
Member
 
Registered: Mar 2004
Location: northern michigan usa
Distribution: Debian Squeeze, Whezzy, Jessie
Posts: 921

Rep: Reputation: 46
Make gawk line work in mawk


Thanks for helping thick headed people like me.

I have a line in a script that works fine in gawk but fresh installs of debian based systems come with mawk instead. On a desktop or laptop that is not an issue really because storage space and cpu power are plentiful. But I wish to use this script on a Pi where storage space and cpu power are in limited supply.

So I would like to change this line to work with mawk, and gawk if possible.

Code:
BLOCKHEAD=$(awk "/\y${data[1]}\y/ {print FNR}" $TMPDIR/tempfile1b)
It fails with this output

Code:
+ w3m -dump -T text/html /home/kingbee/bin/shabbat/data/JPS/et0125.htm
+ sed 1,5d
+ sed -e :a -e '$d;N;2,6ba' -e 'P;D'
+ ((  19 > 1 ))
++ awk '/\y19\y/ {print FNR}' /home/kingbee/bin/shabbat/tmp/tempfile1b
+ BLOCKHEAD=
+ BLOCKHEAD=-1
+ sed -i '1,-1 d' /home/kingbee/bin/shabbat/tmp/tempfile1b
sed: -e expression #1, char 3: unexpected `,'
++ sed -n -e '1 s/^.*19/19/p' /home/kingbee/bin/shabbat/tmp/tempfile1b
+ FIRSTLINE=
With gawk it outputs

Code:
+ w3m -dump -T text/html /home/rbees/bin/shabbat/data/JPS/et0125.htm
+ sed 1,5d
+ sed -e :a -e '$d;N;2,6ba' -e 'P;D'
+ ((  19 > 1 ))
++ awk '/\y19\y/ {print FNR}' /home/rbees/bin/shabbat/tmp/tempfile1b
+ BLOCKHEAD=31
+ BLOCKHEAD=30
+ sed -i '1,30 d' /home/rbees/bin/shabbat/tmp/tempfile1b
++ sed -n -e '1 s/^.*19/19/p' /home/rbees/bin/shabbat/tmp/tempfile1b
+ FIRSTLINE='19 And these are the generations of Isaac, Abraham'\''s son: Abraham begot Isaac. '
+ sed -i '1s/.*/19 And these are the generations of Isaac, Abraham'\''s son: Abraham begot Isaac. /' /home/rbees/bin/shabbat/tmp/tempfile1b
mawk on pi mawk 1.3.3 Nov 1996, Copyright (C) Michael D. Brennan

gawk on Desktop GNU Awk 4.1.4, API: 1.1 (GNU MPFR 3.1.5, GNU MP 6.1.2)
Copyright (C) 1989, 1991-2016 Free Software Foundation.

From what I have read if the versions of mawk and gawk are the same then they are compatible but clearly my versions are not the same.

The desktop is running Wheezy (stable) the pi is running raspbian wheezy.

So is it doable or should I just install gawk?

Note: there are other lines in the script that may fail when conditions hit them but at this point I am not aware of them.

Thanks again for your time.
 
Old 11-04-2018, 10:18 AM   #2
lougavulin
Member
 
Registered: Jul 2018
Distribution: Slackware,x86_64,current
Posts: 279

Rep: Reputation: 100Reputation: 100
I don't have mawk on my system, but
Code:
\y
is specific to gawk, as
Code:
\B, \<, \>, \s, \S, \w, \W, \`, and \'
To test your 'awk' script for both, run gawk with '--posix' option.
 
Old 11-04-2018, 01:24 PM   #3
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,768

Rep: Reputation: 1193Reputation: 1193Reputation: 1193Reputation: 1193Reputation: 1193Reputation: 1193Reputation: 1193Reputation: 1193Reputation: 1193
Try the more commonly supported \< and \> word boundaries:
Code:
BLOCKHEAD=$(awk "/\<${data[1]}\>/ {print FNR}" $TMPDIR/tempfile1b)
 
Old 11-04-2018, 05:18 PM   #4
rbees
Member
 
Registered: Mar 2004
Location: northern michigan usa
Distribution: Debian Squeeze, Whezzy, Jessie
Posts: 921

Original Poster
Rep: Reputation: 46
Thanks lougavulin and MadeInGermany

You gave me what I needed to look for in the man. Comparing what the script actually dose, not that I really remember why, there are extensive changes that have to be made for it to actually work with mawk. That will require to much work that is beyond my programming ability and so will take a lot of time that I can better use for other more important things.

So I install gawk

Thanks again Linux Question users
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Errors trying to compile glibc 2.21 book version 7.7 (Not the mawk-gawk problem) Xenanthropy Linux From Scratch 25 03-29-2015 10:11 AM
[SOLVED] awk / gawk / mawk optimisation rusty_acorn Linux - General 3 10-06-2011 06:06 PM
[SOLVED] gawk -- print in a new line without overwriting januka Programming 6 09-21-2010 01:30 PM
telling glibc to use gawk instead of mawk Virtuality Linux - Newbie 6 01-12-2008 01:22 PM
awk, mawk, gawk - which is "better"? jayeola Programming 8 12-18-2007 08:51 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:03 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration