function ltrim(s) { sub(/^[ \t]+/, "", s); return s }
function rtrim(s) { sub(/[ \t]+$/, "", s); return s }
function trim(s) { return rtrim(ltrim(s)); }
function getfield( xml, fieldname) {
i = index ( xml, "fieldName=\""fieldname"\"");
if(i < 1){
ts = "";
}
else{
ts = substr( xml, i + length("fieldName=\""fieldname"\"") );
ts = substr( ts, index( ts, "value=\"" ) + length( "value=\"" ) );
ts = substr( ts, 1, index( ts, "\"")-1);
gsub(/&/, "&", ts );
if ( index( ts, "," ) > 0 ) ts ="\""ts"\"";
}
return ts;
}
BEGIN { FS = "--------";OFS=",";}
{sub(/..,[A-Z][A-Z]/, "CT-PT")}
{
orig = $0;
# $7 = getfield(orig, "Modalities In Study");
$9 = getfield(orig,"Subject Patients Sex");
$10 = getfield(orig,"Modality Body Region");
$11 = getfield(orig, "Patients Birth Date");
$12 = getfield(orig, "Protocol Name");
$13 = getfield(orig, "Timepoint ID");
print;
}
Everything is working great except for one thing. If iI place this print statement anywhere in the code, it loops in the whole Excel spreadsheet. So basically the print statement appears in every other row. I only want it to appear in the first row: