Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: RE: log files


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: RE: log files
Date   Thu, 5 Aug 2004 18:17:26 +0100

This question is nostalgic. The article below was 
my first public suggestion to the Stata community. 

STB-19  os13  . .  Using awk and fgrep for selective extraction from log files
        . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  N. J. Cox
        5/94    pp.15--17; STB Reprints Vol 4, pp.78--80         (no commands)
        explanation of how to use awk to selectively extract comments
        from log files; explanation of how to use fgrep to selectively
        extract lines from log files

As in another thread, there are shell solutions, 
scripting language solutions, text editor solutions, and Stata solutions. 

These days a more Stataish way to do it would be to use -file- 
to strip the commands. Borrowing some logic from -log2html-, 
this rudimentary program strips lines starting with "{com}" 
from files and otherwise passes lines through: 

*! 1.0.0 NJC 5 August 2004 
program stripcom
	version 8
	syntax anything(name=smclfile) [ , replace ] 
	
	// filenames and handles 
	tempname hi ho
	tempfile resfile
	local ncfile : subinstr local smclfile ".smcl" "" 
	local ncfile : subinstr local ncfile ".SMCL" ""
	local ncfile : subinstr local ncfile `"""' "", all 
	local ncfile : subinstr local ncfile "`" "", all 
	local ncfile : subinstr local ncfile "'" "", all 
	local ncfile `"`ncfile'.nc"'
	
	// line-by-line processing 
	file open `hi' using `"`smclfile'"', r
	file open `ho' using `"`ncfile'"', w `replace'
	
	file read `hi' line
	while r(eof) == 0 {
		if index(`"`line'"', "{com}") != 1 { 
			file write `ho' `"`macval(line)'"' _n
		} 	
		file read `hi' line
	}
	
	file close `ho'
	
	di _n `"no commands file `ncfile' created"' 
end

That's no use unless your log files are in SMCL
(SMCL Makes Cooler Logs)* 

Nick 
n.j.cox@durham.ac.uk 

(or: SMCL Makes Cooler Lectures, as demonstrated by Vince
Wiggins in London in June and in Boston in August) 

Michael S. Hanson
 
> 	I have been wondering if there might be a way to only 
> show command
> results and text explicitly displayed in the log file (or in the
> Results window in certain cases), rather than all the 
> commands as well.
>   Conceptually (I think), a -log- file with the contents of -cmdlog-
> stripped out.  I haven't been able to track down any ado files that
> might achieve that goal....

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index