I have to replace a pattern found in the first uncommented line in a file. The challenge I'm facing is there are several such similar lines but I have to edit only the first uncommented line.
Eg:
#this is example
#/root/xyz:Old_Pattern
/root/xyz:Old_Pattern
/root/xyz:Old_Pattern
Want to change it to
#this is example
#/root/xyz:Old_Pattern
/root/xyz:Changed_Pattern
/root/xyz:Old_Pattern
The only delimiter i can use is ":"
The present code im using is
`sed -ie '1,/^#.*.:.*/!s/:.*/:Changed_Pattern/1' /root/tmp.file`
however it is editing all the similar uncommented lines
Eg; happening #this is example
#/root/xyz:Old_Pattern
/root/xyz:Changed_Pattern
/root/xyz:Changed_Pattern
It works and thanks for your time but I have problem there as I cant give the pattern "Old_Pattern" as that can be anything and I used "*" which didnt work. Im really new to awk so can you help me
---------- Post updated at 03:48 AM ---------- Previous update was at 03:38 AM ----------
Hi michaelrozar17
The code that you have posted deletes all the further lines