Never mind, hex editor showed problem. The line is actually '<table> '. Sorry for the false alarm.
The same if test is applied to the same data in both these awk programs. In the first it works as expected, in the second it blows right past it.
Code:
~/Documents $ awk '{print $0; if ($1 == "<table>") {print "found it"; exit;}}' sccs.txt
<H1><a name="Screen Keyboard Shortcuts">Screen Keyboard Shortcuts</a></H1>
<a href="#Screen Keyboard Shortcuts">Screen Keyboard Shortcuts</a>
<table>
found it
~/Documents $ ht sccs.txt
swx=0<H1><a name="Screen Keyboard Shortcuts">Screen Keyboard Shortcuts</a></H1>
swx=0<a href="#Screen Keyboard Shortcuts">Screen Keyboard Shortcuts</a>
swx=0<table>
swx=0Shortcut Command Description
swx=0^a ' select Prompt for a window name or number to switch to.
swx=0^a " windowlist -b Present a list of all windows for selection.
swx=0^a 0...9 select 0...9 Switch to window number 0...9.
The code for the second program that I run with the alias 'ht' is
Code:
#!/bin/bash
# Creates an html table from each <table>\n ... \n</table> in the document
# In your text, each cell is separated from the next by a single <Tab> character
# There must be the same number of cells in each line of that table
# The end of a table Row must be indicated by an empty line in the text
# meaning that multiple lines of text may be integrated into the same table Row
# Run with ht /file/path, ofilename is ifilename.html
#
awk 'BEGIN {FS = "\t"; OFS = ""; swx = 0}
function prrow(dol, j, b, nb)
{
lin = "<tr>"; for (i = 1; i < j; i++) {lin = lin b dol[i] nb}
delete dol; print lin "</tr>"
}
{
if ($0 == "") {prrow(dol, j, b, nb); b = "<td>"; swy = 1; nb = "</td>"; next}
if ($1 == "<table>") {print "found it"; exit}
if ($1 == "<table>") {b = "<td><b>"; nb = "</b></td>"; swx = 1; print $0; next}
if ($1 == "</table>") {swx = 0; if (swy != 1) {prrow(dol, j, b, nb)}; print $0; next}
if (swx == 0) {print "swx=", swx, $0; next}
for (j = 1; j<= NF; j++) {dol[j] = dol[j] $j "<br>"}
swy = 0
}
' < $1 #> $1'.html'
Any suggestions would be appreciated. Input file is attached.