regular expression search replace

piet22455's Avatar, Join Date: Mar 2010
Newbie Member

Introduction



Hi all,
I have been working the whole day on a one-liner that can do a search replace.. No results jet...

What I need to do:
I have a datafile called data.txt
the content of the datafile:

1? john
2? paul
3? mary
.....
11? stuart
12? peter

And so on. There are 28 lines in the file.

Now I want to change the line that begins with "1?" to "1? Has left the company."

It should be a oneliner that will be called from a batch script.
something like:
perl -p -i -e "s/search/replace" "data.txt"

Does anyone have an idea.. I came up with several variations but ether nothing got replaced or 1 and 10 and 11, etc got replaced.

Any help would be most welcome.

Regards,
Pieter
0
ungalnanban's Avatar, Join Date: Feb 2010
Go4Expert Member
Are you looking for this.

Code:
perl -p -e "s/^1[?]/1? Has left the company./" data.txt
Output:

1? Has left the company. john
2? paul
3? mary
.......
11? stuart
12? peter