Objectmix
Tags Register Mark Forums Read

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 ...


Object Mix > Programming Languages > awk > How to prevent awk from reading escape sequences in AWK strings

Reply

 

LinkBack Thread Tools
  #1  
Old 11-11-2008, 10:05 AM
Junior Member
 
Join Date: Nov 2009
Posts: 0
Application Development is on a distinguished road
Default How to prevent awk from reading escape sequences in AWK strings

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.
  #2  
Old 11-11-2008, 12:34 PM
Junior Member
 
Join Date: Nov 2009
Posts: 0
Application Development is on a distinguished road
Default Re: How to prevent awk from reading escape sequences in AWK strings

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  
Old 11-11-2008, 12:45 PM
Junior Member
 
Join Date: Nov 2009
Posts: 0
Application Development is on a distinguished road
Default Re: How to prevent awk from reading escape sequences in AWK strings

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

Reply

Thread Tools



All times are GMT -5. The time now is 12:41 AM.

Managed by Infnx Pvt Ltd.