Skip to content
Advertisement

Replace a line with a number if part of it is matches using sed

I know this is a very simple question and been discussed many times, but I can’t understand where I am doing wrong in my command.

I would like to replace the lines which starts with “It” as 99999. Each row starts with several blank spaces.

infile.txt
     3
     2
     3
     4
  It is not a number = /home/kayan/data
     3
     5
  It is not a number = /home/kayan/data
     4
     5

I used

sed -i 's/^I/99999/g' infile.txt

But it is not working.

Advertisement

Answer

give this a try:

sed -i 's/^s*It.*/9999/'
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement