In the DOS world, how does one... 
Author Message
 In the DOS world, how does one...

use directory separators correctly? Let me describe the problem.
If I have a batch file which iterates through all the files matching a given
criteria in a given directory, then I use the following syntax:

for %%i in (\test\test*.txt) do call process.bat %%i

Meaning that this would call the batch file process.bat once for each file in the
directory test which matches the file filter test*.txt.

In process.bat, I found that I must do an indirect as in:

gawk < %1 '{gsub("bad","good");print $0}' >deleteme.txt
copy deleteme.txt %1

because the following does not work due to unescaped backslash character in the
path+filename stored in %1:

gawk '{gsub("bad","good");print $0}' %1 >deleteme.txt
copy deleteme.txt %1

However, this has the unwanted effect of setting the FILENAME variable to an empty
string since gawk is not processing a file but a stream that has been indirected.

OK, I can get around this by doing this:

gawk -v currFile=%1 '{gsub("bad","good");print $0}' %1 >deleteme.txt
copy deleteme.txt %1

so that I can use the variable currFile in my awk program and then rather than
trying to access the built-in variable FILENAME, I can access my own variable
currFile. The problem still remains that because I'm using the dos port of gawk,
the directory separator is the backslash character and gawk interprets these to be
escpae sequences in my string.

Any ideas of how I can get around this little problem?

I appreciate any and all help,

Cesar
--
Please remove the uppercase characters from my e-mail address for the real thing



Sun, 01 Apr 2001 03:00:00 GMT  
 In the DOS world, how does one...
I meant to say...

Quote:
> OK, I can get around this by doing this:

> gawk < %1 -v currFile=%1 '{gsub("bad","good");print $0}' >deleteme.txt
> copy deleteme.txt %1

instead of

Quote:
> OK, I can get around this by doing this:
> gawk -v currFile=%1 '{gsub("bad","good");print $0}' %1 >deleteme.txt
> copy deleteme.txt %1

This is what happens when you copy and paste...

Cesar
--
Please remove the uppercase characters from my e-mail address for the real thing



Sun, 01 Apr 2001 03:00:00 GMT  
 In the DOS world, how does one...
Quote:

>use directory separators correctly? Let me describe the problem.
>If I have a batch file which iterates through all the files matching a
given
>criteria in a given directory, then I use the following syntax:

>for %%i in (\test\test*.txt) do call process.bat %%i

>Meaning that this would call the batch file process.bat once for each file
in the
>directory test which matches the file filter test*.txt.

>In process.bat, I found that I must do an indirect as in:

>gawk < %1 '{gsub("bad","good");print $0}' >deleteme.txt
>copy deleteme.txt %1

>because the following does not work due to unescaped backslash character in
the
>path+filename stored in %1:

>gawk '{gsub("bad","good");print $0}' %1 >deleteme.txt
>copy deleteme.txt %1

>However, this has the unwanted effect of setting the FILENAME variable to
an empty
>string since gawk is not processing a file but a stream that has been
indirected.

>OK, I can get around this by doing this:

>gawk -v currFile=%1 '{gsub("bad","good");print $0}' %1 >deleteme.txt
>copy deleteme.txt %1

>so that I can use the variable currFile in my awk program and then rather
than
>trying to access the built-in variable FILENAME, I can access my own
variable
>currFile. The problem still remains that because I'm using the dos port of
gawk,
>the directory separator is the backslash character and gawk interprets
these to be
>escpae sequences in my string.

>Any ideas of how I can get around this little problem?

>I appreciate any and all help,

>Cesar
>--
>Please remove the uppercase characters from my e-mail address for the real

thing

Which version of gawk are you using? I have ver 3.0.3 and with the following
batch file

try_this.bat

gawk "{ print FILENAME; exit }" %1

The following DOS command produced the following output:

[C:\] try_this c:\temp\readme
c:\temp\readme

If the version of gawk I'm using interprets backslashes in filenames as
escape sequences, the \t should have displayed as a tab and the \r as a
carridge return, which would have produced output looking like

eadme    emp

Also, the command you show above

gawk '{gsub("bad","good");print $0}' %1 >deleteme.txt

should generate errors because single quotes aren't string delimiters for
Microsoft's command interpreters COMMAND.COM or CMD.EXE. The command
interpreter would pass   '{gsub("bad","good");print   as the first argument
and   $0}'   as the second. Gawk shouldn't be able to interpret this as a
valid command line program.

Are you using an alternative command interpreter? If so, it's more likely
that the command interpreter is translating backslashes in filenames into
escape sequences.



Mon, 02 Apr 2001 03:00:00 GMT  
 In the DOS world, how does one...

Quote:
>Which version of gawk are you using? I have ver 3.0.3 and with the
following
>batch file

I'm almost positive mine is also 3.0.3 (size is 207,360 bytes). However, I
am looking at the gawk I use at work. Perhaps the version which gave me
trouble (at home) is the older 3.0.2 (which I understand from other postings
was somehat buggy).

Quote:
>try_this.bat
>---------------

>gawk "{ print FILENAME; exit }" %1

>The following DOS command produced the following output:

>[C:\] try_this c:\temp\readme
>c:\temp\readme

OK, I got the same results as you did.
However, there are some problems which don't have anything to do with gawk
independent of version.

If you use the batch file which iterates through the files in a directory as
in:

for %%i in (test\*.bak) do call try_me2.bat %%i

%%i will contain the 8.3 version of the file name which is what gets passed
in to the try_me2.bat that runs gawk

Quote:
>If the version of gawk I'm using interprets backslashes in filenames as
>escape sequences, the \t should have displayed as a tab and the \r as a
>carridge return, which would have produced output looking like

>eadme    emp

>Also, the command you show above

>gawk '{gsub("bad","good");print $0}' %1 >deleteme.txt

>should generate errors because single quotes aren't string delimiters for
>Microsoft's command interpreters COMMAND.COM or CMD.EXE. The command
>interpreter would pass   '{gsub("bad","good");print   as the first argument
>and   $0}'   as the second. Gawk shouldn't be able to interpret this as a
>valid command line program.

It did not generate errors. I have tried using both single and double quotes
to surround the program portion of the gawk command and they both worked.
However, if you need to use a string somewhere in the program then you must
escape the double quotes from COMMAND.COM as in:

gawk "{gsub(\"bad\",\"good\");print $0}" %1 >deleteme.txt

Using the single quotes works as in the unix version of awk/gawk/nawk

Quote:

>Are you using an alternative command interpreter? If so, it's more likely
>that the command interpreter is translating backslashes in filenames into
>escape sequences.

Nope. Windows 95 command.com (file size is 92,870).

Thanks for your help, Harlan. You may be right that my problem is with the
version of the gawk interpreter. I will check that tonight. As for the 8.3
filenames, there's not much that can be done about that. I'll just have to
make sure to keep the names in that format, or else I'll lose the filename.

Cesar



Mon, 02 Apr 2001 03:00:00 GMT  
 In the DOS world, how does one...

Quote:

>Thanks for your help, Harlan. You may be right that my problem is with the
>version of the gawk interpreter. I will check that tonight. As for the 8.3
>filenames, there's not much that can be done about that. I'll just have to
>make sure to keep the names in that format, or else I'll lose the filename.

>Cesar

Solution found for long filename support as well.

See

http://support.microsoft.com/support/kb/articles/q138/1/54.asp

However, Microsoft in their usual wisdom makes the FOR command behave
differently depending if long file name support is on or off

When it is off, %%i contains the full path specified in the parentheses i.e.
the command

for %%i in (test\*.txt) ...

set %%i to

test\test1.txt
test\test2.txt
longfi~1.txt

etc.

but whe enabling LFN the %%i is set only to the filename (no path
prepended), i.e.

test1.txt
test2.txt
long file name.txt

Anyway, this can be handled and is getting a bit off topic for this
newsgroup.

Cesar

Please remove the UPPERCASE characters from my e-mail address for the real
thing



Mon, 02 Apr 2001 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Any one done a commercial Multimedia, authoring system with ST, and in which enviro

2. Any one done a diary system?

3. stumbled on this one doing word search

4. Doing things in one line?

5. Any one doing the similar thing?

6. Some VRML worlds in one HTML page.

7. Oh..help: frames not loading (one is vrml-world)

8. passing info from one world to another

9. several people in one VRML world

10. Multiple Topics - One message -- CA-World discussed too!

11. Climate of fear in the Ada world - one more victim

12. (New) Shareware APL available for IBM PC / DOS world

 

 
Powered by phpBB® Forum Software