sed Command to skip

Friends,

I have 1000 line like below

 
#formate Test.server.e01=http://111.22.33.23/
#test_server_west
Test.server.w01=http://112.123.123.22/
Test.server.w02=http://113.143.123.22/
Test.server.w03=http://112.183.123.22/
 
#test_server_east
Test.server.e01=http://115.123.123.22/
Test.server.e02=http://112.143.123.22/
Test.server.e03=http://116.183.123.22/

my out put of the sed command should be like below

 
#formate Test.server.e01=http://111.22.33.23/
#test_server_west
Test1.server.w01=http://112.123.123.22/
Test1.server.w02=http://113.143.123.22/
Test1.server.w03=http://112.183.123.22/
 
#test_server_east
Test1.server.e01=http://115.123.123.22/
Test1.server.e02=http://112.143.123.22/
Test1.server.e03=http://116.183.123.22/

I need to replace all the string (Test/Test1) but , i need to skip the line which is starting with (#).

Could you please help me on this.

Thanks in Advance,
JB

May be:

sed '/^#/!s/Test/&1/g' file
1 Like

With awk

awk '!/^#/ {sub(/Test/,"Test1")}1' infile
1 Like

Jotne and elixir_sinari both seem to have missed that jothi basu asked not only for a "1" to be added but also for "T" to be changed to "t". And since "Test" always appears at the start of lines to be changed and only appears once, a simpler fix for the given data is:

sed 's/^Test/test1/' file

Of course, if the sample data is not representative, and "Test" actually does appear more than once in some lines or does not always appear at the start of a line, then the more complex scripts shown by others (with code to exclude comment lines) will be needed (with added changes to convert "T" to "t").

1 Like

OP is not clear on the T/t. Example output

Test1.server.w01=http://112.123.123.22/

and

Test/test1

it is typo mistake , it is like (Test/Test1) only

And does it only appear at the start of the a line? Or, can it appear anywhere on a line? Can it appear more than once on a line?