how to replace a certain line using SED in UNIX shell ?

I have a test file that is about 5000 lines long. There are about 30 different lines in this file where each line looks exactly like this:

CODE = 1234

I would like to use a UNIX command (maybe something like sed) to replace that line mentioned above, that is found on exactly line number 575 of that file, to something like this:

CODE = 5678

Keep in mind. I don’t want to change ALL of the lines with the string “CODE = 1234” to “CODE = 5678”. I just want to do this on line 575 of that file.

Does anyone know how I can do this in UNIX shell? Thanks.

sed ‘575s/CODE = 1234/CODE = 5678/’ file > newfile

awk


awk -F"=" 'NR==575{$2=5678}1' OFS="=" file

opensuse2009 wrote:
> I have a test file that is about 5000 lines long. There are about 30
> different lines in this file where each line looks exactly like this:
>
> CODE = 1234
>
>
> I would like to use a UNIX command (maybe something like sed) to
> replace that line mentioned above, that is found on exactly line number
> 575 of that file, to something like this:
>
> CODE = 5678
>
>
> Keep in mind. I don’t want to change ALL of the lines with the string
> “CODE = 1234” to “CODE = 5678”. I just want to do this on line 575 of
> that file.
>
> Does anyone know how I can do this in UNIX shell? Thanks.
>
>

sed ‘575s/CODE = 1234/CODE = 5678/’

Sed doesn’t do in place edit… but GNU sed does have
a (non portable) -i option for in place editing.