read_output <- function(fname="U.prn", 
                        nobs=6) {
## read in  INS
ins=readLines("U.ins")
## To read in output
output=file("U.prn","r")
results=c()
for(i in 2:length(ins)){
 ## Read l command
 nlines=as.numeric(sub("^l(\\d+) .*","\\1",ins[i]))
 ## Read that many lines
 text=readLines(output,nlines) ##e.g. l5 for nlines=5
 print(tail(text,1)) ## to check whether it's reading the right line
 ## Read variable name e.g. (c1)
 var=sub(".* \\((.*)\\).*","\\1",perl = TRUE,ins[i])
 ## Read start and end character numbers
 start.char=as.numeric(sub(".*\\)(\\d+):\\d+","\\1",perl = TRUE,ins[i]))
 end.char=as.numeric(sub(".*\\)\\d+:(\\d+)","\\1",perl = TRUE,ins[i]))
 ## Read variable value ## e.g. 36:50
 val=as.numeric(substr(tail(text,1),start.char,end.char)) 
 names(val)=var
 results=c(results,val)
}
close(output)

return(results)

} # 'read_output' END