Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: st: log file lines numbers - can they be created/inserted


From   Nick Cox <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   RE: st: log file lines numbers - can they be created/inserted
Date   Thu, 18 Nov 2010 18:42:04 +0000

Vim is my favourite. 

Nick 
[email protected] 

Ben Hoen

Thanks Guys!

Nick, what, pray-tell, is the "smart" text editor you use?  (Mine - Notepad
- is evidently as dumb as a doornail.)

Nick Cox

Interesting question. Absent any option for this in -log- that I can see, an
evident alternative is to do it after the fact. 

In my own favourite text editor, there is an easy way to show line numbers,
and probably a way to add line numbers, and what one smart text editor can
do, another can. 

Alternatively, this quick and dirty utility passed precisely one test: 

*! 0.0.1 NJC 18 Nov 2010 
program lineno
	version 11.0
	syntax anything(name=file) , saving(str) [ replace ] 

	if "`replace'" == "" {
		confirm new file `"`saving'"' 
	}  

	tempname hi ho
	file open `hi' using `"`file'"', r
	file open `ho' using `"`saving'"', w `replace'
	file read `hi' line
	local i = 1 
	
	while r(eof) == 0 {
		file write `ho' "`i' " `"`macval(line)'"' _n
		file read `hi' line
		local ++i 
	}
	
	file close `ho'
end

Perhaps 11.0 can be decreased; meaning, I didn't test this in Stata 10 or
lower. 

The code points up one tricky point: in just copying lines, you must be
careful to inhibit macro substitution. 


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index