ref: 703960d83de310d26c273c79c2f9abdd645e1eda
dir: /test/T.split.broken/
#!/bin/rc
echo T.split: misc tests of field splitting and split command >[1=2]
TEMP0=foo0
TEMP1=foo1
TEMP2=foo2
$awk 'BEGIN {
# Assign string to $0, then change FS.
FS = ":"
$0="a:bc:def"
FS = "-"
print FS, $1, NF
# Assign number to $0, then change FS.
FS = "2"
$0=1212121
FS="3"
print FS, $1, NF
}' > $TEMP1
echo '- a 3
3 1 4' > $TEMP2
diff $TEMP1 $TEMP2 || echo 'BAD: T.split: 0.1' >[1=2]
# getline var shouldn't impact fields.
sed 1000q /lib/ucd/UnicodeData.txt >foo.txt
echo 'f b a' > $TEMP0
$awk '{
FS = ":"
getline a < "foo.txt"
print $1
}' $TEMP0 > $TEMP1
echo 'f' > $TEMP2
diff $TEMP1 $TEMP2 || echo 'BAD: T.split: 0.4' >[1=2]
echo 'a b c d
foo
e f g h i
bar' > $TEMP0
$awk '{
FS=":"
getline v
print $2, NF
FS=" "
}' $TEMP0 > $TEMP1
echo 'b 4
f 5' > $TEMP2
diff $TEMP1 $TEMP2 || echo 'BAD: T.split: 0.5' >[1=2]
echo 'a.b.c=d.e.f
g.h.i=j.k.l
m.n.o=p.q.r' > $TEMP0
echo 'b
h
n' > $TEMP1
$awk 'BEGIN { FS="=" } { FS="."; $0=$1; print $2; FS="="; }' $TEMP0 > $TEMP2
diff $TEMP1 $TEMP2 || echo 'BAD: T.split: record assignment 1' >[1=2]
echo 'a.b.c=d.e.f
g.h.i=j.k.l
m.n.o=p.q.r' > $TEMP0
echo 'd.e.f
b
j.k.l
h
p.q.r
n' > $TEMP1
$awk 'BEGIN { FS="=" } { print $2; FS="."; $0=$1; print $2; FS="="; }' $TEMP0 > $TEMP2
diff $TEMP1 $TEMP2 || echo 'BAD: T.split: record assignment 2' >[1=2]
echo 'abc
de
f
' > $TEMP0
who | sed 10q >> $TEMP0
sed 10q foo.txt >> $TEMP0
$awk '
{ n = split($0, x, //)
m = length($0)
if (m != n) print "error 1", NR
s = ""
for (i = 1; i <= m; i++)
s = s x[i]
if (s != $0) print "error 2", NR
print s
}' $TEMP0 > $TEMP1
diff $TEMP0 $TEMP1 || echo 'BAD: T.split: //' >[1=2]