I have a question.  Is there a way to have a replacement list and apply it to a buffer? I mean if I have in a file:

period1,feb-12
period2,jun-10
report,CR

and I want to replace all the instances of the first word in a completely differentbuffer(which have many of the first words) is there an easy way?

EDIT: I think I made my post kinda ambigous, sorry for that. I meant that I have two files. One is the one I want to edit by replacing the words. The other file is one that has replacement rules.
1
Piotr Romanus's profile photoElias Mårtenson's profile photoGianfranco Arroyo's profile photoNick Alcock's profile photo
6 comments
 
How about "M-x query-replace-regexp" with the following from regular expression: "^.*,"
 
I don't think you can do it without a bit of programming. Since I am not a elisp expert I would suggest sed and a bit of bash scripting. Something like the following:

#!/bin/bash

rules_file=<file_with_replacement_words>
from_file=<file_with_original_text>
to_file=$from_file.replace
cp -f $from_file $to_file

while read line; do 
    from_word=`echo $line | cut -f1 -d','`
    to_word=`echo $line | cut -f2 -d','`
    sed -i "s/$from_word/$to_word/g" $to_file
done < $rules_file
 
+Piotr Romanus, that only works as long as from_word and to_word don't contain spaces: you forgot to quote the assignments. It also works only as long as neither contain slashes.

I think elisp is a better choice.
 
I dont mind learning some elisp. I wanted to do it already so this is like a good project to start.
 
I always do stuff like that using a keyboard macro. I open two buffers and let the keyboard macro switch between them.
 
+Elias Mårtenson, it is one of my abiding shames that I find elisp so convenient that I've never learned to use keyboard macros for anything. I really should.
Add a comment...