i have little challenge, help me out.i have a file where i have a value declared and and i have to replace the value when called. for example i have the value for abc and ccc. now i have to substitute the value of
value abc and ccc in the place of them.
Input File:
go to &abc=ddd;
if file found &ccc=10;
no the value name is &abc;
and the age is &ccc;
Output:
go to &abc=ddd;
if file found &ccc=10;
now the value name is ddd;
and the age is 10;
Hi Yoda,
It is not working for the complex things like the text below: i have 500 to 1000 lines in the txt file which i have to replace.
I have a lerarne a &lesson=ddd;
which i have to for &mm=22;
asdfasd &G=3;
sad &aa=sss
sor sdfsdf dsfsdfs &lesson
saasdasdasd
d ther asdfadd &lesson
asda &aa
asdasdasd&AA
You are not quite consistent between your specifications: sometimes the "variables" are terminated with a ";" sometimes they are not. Remove the -1 from RLENGTH if you want it included.
Assuming that you are using the variable after assigning it on the file...(else it will print a blank in place of &xxx string)
$ perl -pe '$hash{$1}=$2 if /\&(\w+)\=(\w+)/;s/\&(\w++)(?!\=)/$hash{$1}/g;' file
go to &abc=ddd;
if file found &ccc=10;
no the value name is ddd;
and the age is 10;
well, i think you need an elaborate script to satisfy all your needs.
Space can be overcome easily, but the assignment statement itself seems to have substitutions of variables. It is very much possible to do this, but not something I can attempt in the middle of my work here.
You can take the lead from all the suggestions posted and try yourself.