How to prevent awk from reading escape sequences in AWK strings : awk
This is a discussion on How to prevent awk from reading escape sequences in AWK strings within the awk forums in Programming Languages category; Hi I have the following problem. I have build an installer for windows, which uses an awk script in the process. The installer just edits (text replace) awk-script with the the proper path of a certain file. e.g. I have a variable in that awk script that holds path information: (Installer outputs the right hand side) LogFormat = "'C:\Program Files\Logs\System Log %Y-%m- %d.txt'" The idea would be that the installer would output a proper path to the awk script and the scipt would be then run. The problem is that the installer outputs only a single backslash (as normal windows ...
![]() |
| | LinkBack | Thread Tools |
|
#1
| |||
| |||
| I have the following problem. I have build an installer for windows, which uses an awk script in the process. The installer just edits (text replace) awk-script with the the proper path of a certain file. e.g. I have a variable in that awk script that holds path information: (Installer outputs the right hand side) LogFormat = "'C:\Program Files\Logs\System Log %Y-%m- %d.txt'" The idea would be that the installer would output a proper path to the awk script and the scipt would be then run. The problem is that the installer outputs only a single backslash (as normal windows programs display a path) . However single backslashes need to be replaced with a double backslash since this information goes directly to a awk variable. I would need a series of awk commands that can turn the contents of the above variable into "'C:\\Program Files\\Logs\\System Log %Y-%m-%d.txt'" with random paths e.g. replace backslashes with double backslashes. I tryed this with gsup but i was not able to make it work. |
|
#2
| |||
| |||
| juhanay@gmail.com wrote: > Hi > I have the following problem. I have build an installer for windows, > which uses an awk script in the process. The installer just edits > (text replace) awk-script with the the proper path of a certain file. > e.g. > > I have a variable in that awk script that holds path information: > (Installer outputs the right hand side) > > LogFormat = "'C:\Program Files\Logs\System Log %Y-%m- > %d.txt'" > > The idea would be that the installer would output a proper path to the > awk script and the scipt would be then run. The problem is that the > installer outputs only a single backslash (as normal windows programs > display a path) . However single backslashes need to be replaced with > a double backslash since this information goes directly to a awk > variable. > > I would need a series of awk commands that can turn the contents of > the above variable into > > "'C:\\Program Files\\Logs\\System Log %Y-%m-%d.txt'" > > with random paths e.g. replace backslashes with double backslashes. I > tryed this with gsup but i was not able to make it work. awk '{gsub(/\\/,"\\\\")}1' infile >outfile Make sure (by introducing a proper condition in front of the action) that no unintended backslashes in your input file will be replaced. Janis |
|
#3
| |||
| |||
| In article <gfcfnb$d8b$1@svr7.m-online.net>, Janis Papanagnou <janis_papanagnou@hotmail.com> wrote: .... > awk '{gsub(/\\/,"\\\\")}1' infile >outfile Small improvement (a little clearer - and it works for doubling anything): {gsub(/\\/,"&&")} 1 |


