0
votes

I'm new to tcl. I'm trying to run some commands with tcl script.

I searched online and came to know that we can run unix commands with tcl using exec

I executed the following;

perl -i -p -e 's/hello linux./hello fedora. /g;' sample1.txt

from the commandline and it worked. it replaced all the occurences of hello linux with hello fedora.

I tried executing the same command in my tcl script.

set result [exec perl -i -p -e 's/hello linux./hello fedora. /g;' sample.txt]

I got the below error :

child process exited abnormally

I also tried using sed command. I got the same error. I guess there is something wrong with the syntax. I searched online but i couldn't figure it out on my own.

1

1 Answers

2
votes

' is not a grouping character in tcl. The equivalent grouping in tcl is {}. Therefore the correct statement is:

exec perl -i -p -e {s/hello linux./hello fedora. /g;} sample.txt

Or even:

exec perl -i -p -e "s/hello linux./hello fedora. /g;" sample.txt