-1

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?

Thomas Dickey
  • 76,765

1 Answers1

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