-1

This question already has an answer here:

Here is an example of what I am trying to do:

#!/bin/bash
Update=$1

if [$Update == Value] 
then
    NewValue= $Update
    vi %s/Value/$NewValue/g > Updatedfile
fi
exit 0

Is there a way to utilize vi commands within a script? My thoughts are that some type of piping would do this?

marked as duplicate by jasonwryan, Stephen Kitt, Anthon, G-Man, don_crissti Jul 14 '15 at 21:37

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Ahh, I was thinking sed, though did not want to assume that was the only command or technique. – Juan Davila Jul 14 '15 at 21:20
3

Yes, you can use vi commands in a stript: sedstream editor, is a member of the vi family (ed, vi, sed). It is used to edit streams of data passed via pipes, so just what you need. It also uses same commands as vi.

e.g. To process standard in and put result in Updatedfile

sed -e "s/Value/$NewValue/g" > Updatedfile

see also -i option, to edit in-place.

  • Thanks for your answer Richard, you answer was helpful, though I was more concerned on how to use a loop statement, this initially solves the problem of using sed. – Juan Davila Aug 28 '15 at 16:49

Not the answer you're looking for? Browse other questions tagged or ask your own question.