Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 803441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T23:45:42+00:00 2026-05-14T23:45:42+00:00

In Python, you might do something like fout = open(‘out’,’w’) fin = open(‘in’) for

  • 0

In Python, you might do something like

fout = open('out','w')
fin = open('in')
for line in fin:
    fout.write(process(line)+"\n")
fin.close()
fout.close()

(I think it would be similar in many other languages as well).
In Emacs Lisp, would you do something like

(find-file 'out')
(setq fout (current-buffer)
(find-file 'in')
(setq fin (current-buffer)
(while moreLines
 (setq begin (point))
 (move-end-of-line 1)
 (setq line (buffer-substring-no-properties begin (point))
 ;; maybe
 (print (process line) fout)
 ;; or
 (save-excursion 
  (set-buffer fout)
  (insert (process line)))
 (setq moreLines (= 0 (forward-line 1))))
(kill-buffer fin)
(kill-buffer fout)

which I got inspiration (and code) from Emacs Lisp: Process a File line-by-line. Or should I try something entirely different? And how to remove the "" from the print statement?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T23:45:42+00:00Added an answer on May 14, 2026 at 11:45 pm

    If you actually want batch processing of stdin and sending the result to stdout, you can use the –script command line option to Emacs, which will enable you to write code that reads from stdin and writes to stdout and stderr.

    Here is an example program which is like cat, except that it reverses each line:

    #!/usr/local/bin/emacs --script
    ;;-*- mode: emacs-lisp;-*-
    
    (defun process (string)
      "just reverse the string"
      (concat (nreverse (string-to-list string))))
    
    (condition-case nil
        (let (line)
          ;; commented out b/c not relevant for `cat`, but potentially useful
          ;; (princ "argv is ")
          ;; (princ argv)
          ;; (princ "\n")
          ;; (princ "command-line-args is" )
          ;; (princ command-line-args)
          ;; (princ "\n")
    
          (while (setq line (read-from-minibuffer ""))
            (princ (process line))
            (princ "\n")))
      (error nil))
    

    Now, if you had a file named stuff.txt which contained

    abcd
    1234
    xyz
    

    And you invoked the shell script written above like so (assuming it is named rcat):

    rcat < stuff.txt
    

    you will see the following printed to stdout:

    dcba
    4321
    zyx
    

    So, contrary to popular belief, you can actually do batch file processing on stdin and not actually have to read the entire file in at once.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 442k
  • Answers 442k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Just do a quick check to see if the date… May 15, 2026 at 5:54 pm
  • Editorial Team
    Editorial Team added an answer Just a rough guess, because I don't know your complete… May 15, 2026 at 5:54 pm
  • Editorial Team
    Editorial Team added an answer Here is another version I actually made for a friend… May 15, 2026 at 5:54 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.