How do I replace only if the keyword is at the begining of a line?
Code:
--
a = �This is a print statement�
print a
--
What if I want to replace print by #print only in the second line i.e only if the line starts with that keyword.
Please help me out. I'm new to SED.
-----Post Update-----
I need a SED command. Please help. I couldn't find about it anywhere and had to start a new thread.
For some reason the above code does not seem to work.
This is my code:
<--START
a = "This is a print statement
print a
b = "This contains print statement"
print b
END-->
DESIRED:
<--START
a = "This is a print statement #print a
b = "This contains print statement" #print b
END-->
Line 4 of the code (print b) should also be commented i.e tabs and space before the first word should be taken care of.
I'm trying to use:
sed 's/[^][pP][rR][iI][nN][tT]/#print/'
sed 's/^[pP][rR][iI][nN][tT]/#print/'
But nothing happens. No part of the code is commented.
If I use:
sed 's/[pP][rR][iI][nN][tT]/#print/'
The first occurence is commented correctly but I want it to be commented only if the line starts with the keyword.
> cat a.txt
a = "This is a print statement
print a
b = "This contains print statement"
print b
>
>
>
> sed 's/^[pP][rR][iI][nN][tT]/#print/' a.txt
a = "This is a print statement #print a
b = "This contains print statement" #print b