Go4Expert (http://www.go4expert.com/)
-   Perl (http://www.go4expert.com/forums/perl/)
-   -   regular expression search replace (http://www.go4expert.com/forums/regular-expression-search-replace-t21210/)

piet22455 5Mar2010 18:53

regular expression search replace


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.


ungalnanban 6Mar2010 11:59

Re: regular expression search replace
Are you looking for this.


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

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

All times are GMT +5.5. The time now is 21:21.