From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: pjb@informatimago.com (Pascal J. Bourguignon) Newsgroups: gmane.emacs.help Subject: Re: printing columns into a file Date: Mon, 28 Dec 2009 12:49:05 +0100 Organization: Informatimago Message-ID: <871vif1fpq.fsf@hubble.informatimago.com> References: <3e9fd39f-2c27-49a5-9f33-51020c58cba2@u7g2000yqm.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1262004200 17306 80.91.229.12 (28 Dec 2009 12:43:20 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 28 Dec 2009 12:43:20 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Dec 28 13:43:13 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1NPEuV-0001vW-La for geh-help-gnu-emacs@m.gmane.org; Mon, 28 Dec 2009 13:42:06 +0100 Original-Received: from localhost ([127.0.0.1]:41086 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NPEuO-0004iT-C4 for geh-help-gnu-emacs@m.gmane.org; Mon, 28 Dec 2009 07:41:12 -0500 Original-Path: news.stanford.edu!usenet.stanford.edu!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 89 Original-X-Trace: individual.net OGpd/cYkSbz2udOp3Z/2CQF3t2+zjihe4oCIBlkSnsyr5d1v2V Cancel-Lock: sha1:Yjg5MWQ2ZmE3NTczZjZmZWJkMTFjNDllY2U5NTNjZjhiMzFhMWIyNQ== sha1:IUBGNCov85/VHdz7AteY8WVgvlg= Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9 033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR mV+hO/VvFAAAAABJRU5ErkJggg== X-Accept-Language: fr, es, en X-Disabled: X-No-Archive: no User-Agent: Gnus/5.101 (Gnus v5.10.10) Emacs/22.3 (gnu/linux) Original-Xref: news.stanford.edu gnu.emacs.help:175832 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:70906 Archived-At: Jin writes: > Hi, > > I will really appreciate any help on this! > > I have a file looking like the following > > date month year > > 12 5 1982 > 30 6 1982 > 3 1982 > 28 1877 > 30 2 1888 > > As you can see, my file has blanks in a column, but I like to keep it > that way. > When I tried to use awk to print each column into a separate file > (date.txt, month.txt, and year.txt), > it doesn't retain the blank information on emacs but moves the value > below upward to cover the blank. So, it'd be like > > date.txt > 12 > 30 > 28 > 30 > > month.txt > 5 > 6 > 3 > 2 > > How can I keep the blank as it is in the original fiile? So this is an awk question? man awk Otherwise you could do it in emacs: (require 'cl) (defmacro* dolines (start-end &body body) "Executes the body with start-var and end-var bound to the start and the end of each lines of the current buffer in turn." (let ((vline (gensym))) (destructuring-bind (start-var end-var) start-end `(let ((sm (make-marker)) (em (make-marker))) (unwind-protect (progn (goto-char (point-min)) (while (< (point) (point-max)) (let ((,vline (point))) (set-marker sm (point)) (set-marker em (progn (end-of-line) (point))) (let ((,start-var (marker-position sm)) (,end-var (marker-position em))) ,@body) (goto-char ,vline) (forward-line 1)))) (set-marker sm nil) (set-marker em nil)) nil)))) (dolines (start end) (goto-char start) (when (re-search-forward "^\\( *?[0-9]*\\)\\( *?[0-9]*\\)\\( *[0-9]*\\)$" end t) (let ((day (match-string 1)) (month (match-string 2)) (year (match-string 3))) (with-current-buffer (get-buffer-create "day.txt") (insert day "\n")) (with-current-buffer (get-buffer-create "month.txt") (insert month "\n")) (with-current-buffer (get-buffer-create "year.txt") (insert year "\n"))))) -- __Pascal Bourguignon__ http://www.informatimago.com/