Re: [gnix] Need a Program that changes content of a file
[In reply to]

Can't Post

Hello gnix, You have already answered the query but I wondered if the person who had originally posted the query checked the solution proposed by you. In fact I checked it and I found out that it needs a minor improvement You see while<IN> and then the substitution works well for the first two lines but fails in the last input line because the last input line is also carrying a white space character (You check it yourself;only the first two lines are changed) so I had modified the code a bit and my solution is as follows #!/usr/bin/perl -w $filename = "text.txt"; open(IN, "<$filename") || die "Can't open $filename"; open(OUT,">new_$filename") || die "Can't open new_$filename"; while(<IN>) { s/^([a-z]+)=\d{1,2}\s*$/$1=3/g; print OUT $_,"\n"; } close(IN); close(OUT); Now it will also change the last line (i.e usrpass=10) previously it was changing only the first two lines. As far as digits are concerned I used \d{1,2} because all the three lines of input had either one or two digits only.

Quote

Criticism is very welcome because it improves me-For all my suggestions " I am sure someone else can do it in a better or elegant manner!"

Re: [KevinR] Need a Program that changes content of a file
[In reply to]

Can't Post

After the veteran's comment I re-tried it but this time using my mouse I carefully placed the cursor next to the last character a zero in this case and pressed the "delete-key" on my keyboard for a few seconds and now the original solution proposed was working without a \s* required. I understand that it is always advisable to repeat this feet (press the del key few times or keep it pressed for a few seconds after the last character in your input file) when working on files otherwise this "copy-paste artifact" may creep in or use \s* in the regex capture and/or s//. Am I right-For all my suggestions " I am sure someone else can do it in a better or elegant manner!"