Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run on commandline but not in batch script (windows)

Status
Not open for further replies.

pigna

Programmer
Nov 9, 2006
10
NL
To explain my question I build a small testcase. I have a command that seems to run fine when executed on commandline in windows:

C:\Tools\gawk>echo Hello World|gawk "{ for (i = 1; i <= NF ; i++) printf \"%s\t\", substr($i,1,7); }"
Hello World


However when I do run it in a cmd file it goes wrong:
C:\Tools\gawk>test
C:\Tools\gawk>echo Hello World | gawk "{ for (i = 1; i <= NF ; i++) printf \"s\t\", substr($i,1,7); }"
s s


Anyone who can explain this?






 
You omitted a % character in the second run ???

Or the cmd interpreter has eaten it?

In that case, try doubling it or quoting it with a backslash like you did for the embedded double quotes in the file test.cmd


HTH,

p5wizard
 
Hi

On Windows I would run [tt]awk[/tt] scripts from file, because the escaping is negligibly weak in cmd.exe.
Code:
[blue]C:\>[/blue] type script.awk
{ for (i = 1; i <= NF ; i++) printf "%s\t", substr($i,1,7); }

[blue]C:\>[/blue] echo Hello World | gawk -f script.awk
Hello   World

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top