awk automatically splits data into records, records into fields.
awk automatically chooses data type string or numeric by expression context.
awk variables have default values of empty string (or zero in numeric context).
awk programs can be entered on the command line.

Hence, to be more effective than awk you'd need to write a j command shorter 
than

gawk -F\; '{print $1+$2}'

The j program will need to find the first two fields on each line, convert 
strings to numeric type, evaluate and show the sum, and finally exit 0 .  If I 
wrote the program I'd either need to append '0;0' to lines or pepper the code 
with adverse adjectives.  None of these steps are long in j, and I'm sure will 
fit onto the command line.

gawk is the best tool I know of for many "reform document" tasks.

With apologies to those who don't read bash, here's a complete example.  
Replace  gawk -F\; '{print $1+$2}'  with your j command.  For fair comparison, 
the j command will be similar to
$ jconsole -js 'exit 0[echo 2*98'
Because of aliases, including a standard script to preload awk definitions is 
reasonable.
$ gawk -F\; '{print $1+$2}' <<EOF
1 ; 2 ;  line 1   BEGIN{ FS=";" }{print $1+$2}
4;7; some other ; text
9

8 ;
EOF
3
11
9
0
8
$

Date: Fri, 14 Feb 2014 21:51:32 -0500
From: Lee Fallat <[email protected]>
To: [email protected]
Subject: [Jprogramming]  awk-like J sentences?
Message-ID:
        <cakzhxzfvapq56dnmsnxw6fqvfz7f__5bwdtkns+ut5vb7sb...@mail.gmail.com>

BEGIN { FS=";" }
{ print $1+$2 }

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to