Artificial intelligent assistant

substitute at beginning of line I want to search a pattern and insert a character at the beginning of a line using `regsub` in TcL. I have to use TcL only ## Input file mna1 x a1 vss vbn nch_svt_mac nfin=nfin_n1 l=ln1 mna2 x a2 vss vbn nch_svt_mac nfin=nfin_n2 l=ln2 mpa2 vdd a2 net10 vbp pch_mac nfin=nfin_p2 l=lp2 mpa1 net10 a1 x vbp pch_svt_mac nfin=nfin_p1 l=lp1 ## Desired output mna1 x a1 vss vbn nch_svt_mac nfin=nfin_n1 l=ln1 mna2 x a2 vss vbn nch_svt_mac nfin=nfin_n2 l=ln2 *mpa2 vdd a2 net10 vbp pch_mac nfin=nfin_p2 l=lp2 mpa1 net10 a1 x vbp pch_svt_mac nfin=nfin_p1 l=lp1 ## command used regsub -nocase {pch_mac} $file_pointer {\*$1} file_pointer

If you want to add text at the _beginning_ of the line, you have to match all the characters from the beginning of the line:


regsub {^.*pch_mac} $file_pointer {*&} file_pointer


Here, `&` in the replacement part is substituted with all the text that matched the expression, i.e. all the chars from the beginning of the line to "pch_mac". See <

Perl uses the `$1` notation, Tcl uses `\1` **if** you use capturing parentheses:


regsub {^(.*pch_mac)} $file_pointer {*\1} file_pointer


Another way to write this is


if {[string first pch_mac $file_pointer] != -1} {
set file_pointer "*$file_pointer"
}

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 02033e71b9a148d02ace62e0e86adad3