|
|
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.
|
|
0
|
|
|
|
Reply
|
juhanay (3)
|
11/11/2008 3:05:39 PM |
|
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
|
|
0
|
|
|
|
Reply
|
Janis
|
11/11/2008 5:34:34 PM
|
|
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
|
|
0
|
|
|
|
Reply
|
gazelle
|
11/11/2008 5:45:22 PM
|
|
On 11 marras, 19:45, gaze...@shell.xmission.com (Kenny McCormack)
wrote:
> In article <gfcfnb$d8...@svr7.m-online.net>,
> Janis Papanagnou =A0<janis_papanag...@hotmail.com> wrote:
> ...
>
> > =A0 awk '{gsub(/\\/,"\\\\")}1' infile >outfile
>
> Small improvement (a little clearer - and it works for doubling anything)=
:
>
> {gsub(/\\/,"&&")}
> 1
Thanks for the replys. I the above method works for 100% and I will
use it, if there is no other way. I was looking for a way that would
allow sigle quotes like in Perl. E.g. No data is altered in single
quotes. Another possibility would be that the installer would output
the string "C:\Program Files\Logs\System Log %Y-%m-
%d.txt" to awk-source code and then I would use gsub somehow to modify
that string at runtime.
|
|
0
|
|
|
|
Reply
|
juhanay
|
11/17/2008 2:06:13 PM
|
|
juhanay@gmail.com wrote:
> On 11 marras, 19:45, gaze...@shell.xmission.com (Kenny McCormack)
> wrote:
>
>>In article <gfcfnb$d8...@svr7.m-online.net>,
>>Janis Papanagnou <janis_papanag...@hotmail.com> wrote:
>>...
>>
>>
>>> awk '{gsub(/\\/,"\\\\")}1' infile >outfile
>>
>>Small improvement (a little clearer - and it works for doubling anything):
>>
>>{gsub(/\\/,"&&")}
>>1
>
>
> Thanks for the replys. I the above method works for 100% and I will
> use it, if there is no other way. I was looking for a way that would
> allow sigle quotes like in Perl.
That's an easy answer; you're using awk and there is no single quote
syntax construct as in perl or shell or...; because a backslash is a
special escape character.
> E.g. No data is altered in single
> quotes. Another possibility would be that the installer would output
> the string "C:\Program Files\Logs\System Log %Y-%m-
> %d.txt" to awk-source code and then I would use gsub somehow to modify
> that string at runtime.
There are two inherent "problems" here...
1. Backslash is an _escape character_ that needs special handling.
This got popular from Unix world where you can find it everywhere;
in the shell, in the C language, in awk, and many other Unix tools.
2. The WinDOS platform uses a _common escape character_ - which had
been in use long before Bill left his garage! - as a delimiter for
the very common path components; with that historic background this
is a severe misdesign.
Janis
|
|
0
|
|
|
|
Reply
|
Janis
|
11/17/2008 2:50:17 PM
|
|
|
4 Replies
273 Views
(page loaded in 0.053 seconds)
Similiar Articles: how to clear screen in unix - fn. similar to clrscr() in DOS ...All strings clear the screen if and only if the ... The basic trick is to start an "escape sequence" with one ... 256 characters and codes, how to - comp.lang.awk how ... ANSI terminal escape sequence regexp - comp.unix.shell... This will go wrong for those sequences that can include quoted strings ... It might be easier to read though ... be used in RS? - comp.lang.awk ANSI terminal escape sequence ... bigger memory allocation for Gawk - comp.lang.awk... is choking because it's trying to read the ... use single rather than double quotes: awk -vRS=' \\$' With double quotes, keep ... newlines replaced by spaces, and $ sequences ... changing lf-only to crlf - comp.lang.awkHere's a little quickie I've found useful (I'm loving awk!). I get files that have ... I used to open any "questionable" files with wordpad, which I found could read *nix ... ANSI 256 characters and codes, how to - comp.lang.awkI want to read text files and make ... all but last character - comp.lang.awk ... ANSI terminal escape sequence ... ... Converting UTF-16 character strings to ISO8859 ... Finding common lines between text files - comp.unix.programmer ...You can get the same effect with temporary files, but if you can avoid temporary ... Find word, replace line - comp.lang.awk reading the previous line in a text file - comp ... How to strip comments out of code - comp.lang.java.programmer ...That is, the line numbers, positions, and escape sequences of the ... How may decimal places SAS keep when do calculation ... characters? ... non ASCII characters - comp.lang.awk ... using cat and << - comp.unix.shell... the entire string argument for formatting strings and escape sequences ... you'll stop posturing and everyone can stop ... Two-way pipe on an awk process - comp.lang.awk ... perl + regex bug? - comp.lang.perl.miscPlease read the Posting ... in the combinatorial strings. The combinatorial strings are a sequence of ... value U+0900 - comp.lang.awk ANSI terminal escape sequence ... remove any commas/data from mysql? - comp.databases.mysql ...Generally comma separated fields expect strings (especially ... far my removal of the commas is the only way I can stop ... mysql 6566 articles. 7 followers. ... lang.awk How do I ... How to prevent awk from reading escape sequences in AWK stringsHow 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 - awk ... Awk - A Tutorial and Introduction - by Bruce Barnett... can search for particular strings and modify the output. AWK ... to an empty string, then AWK will read ... +-----+ | AWK Table 5 | | Escape Sequences | |Sequence ... 7/25/2012 9:40:45 PM
|
|
|
|
|
|
|
|
|