vim, ed or sed multiple search and replace on a given file -


i want series of "search , replace" on given file, file.txt. example,

s/foo/bar/g s/abc/xyz/g s/pqr/lmn/ g/string-delete/d  

and on.

how shuld write these actions in script file , run them on single go on target file.txt save newfile.txt?

i saw post search , replace variables in file using bash/sed somehow couldn't work me.

edit: prefer vim/ed based solution thanx tempora

you write function wrap commands, , call function.

note !!

the function below example, added % in front of s cmd. because guess want substitution on whole buffer, not on "current" line. have careful, in way, previous replaced result replaced again latter command, if latter pattern matched. adjust needs.

e.g. think about:

text: fooc have %s/foo/ab/g , %s/abc/def/g

fun! execthem()     %s/foo/bar/g     %s/abc/xyz/g     %s/pqr/lmn/g     g/string-delete/d endf 

source function, then

:call execthem() 

will job.

you of course create command that:

command mybatch call execthem() 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -