Link to home
Start Free TrialLog in
Avatar of prgeorge3383
prgeorge3383

asked on

awk in windows

This works fine in linux /unix
cat file.txt    |   awk -F ";" '{  printf(",%s,%s,%s,%s,\n", substr($21,0,10),$99,$105,$104)}' > lrep_1.txt
i am trying to run this in windows like this
cat file.txt    |  g awk -F ";" '{  printf(",%s,%s,%s,%s,\n", substr($21,0,10),$99,$105,$104)}' > lrep_1.txt

Attached is the error

C:\iscripts>cat file.txt    |   gawk -F ";" '{  printf(",%s,
%s,%s,%s,\n", substr($21,0,10),$99,$105,$104)}' > lrep_1.txt
gawk: cmd. line:1: '{
gawk: cmd. line:1: ^ Invalid char ''' in expression

Thanks for the help in advance
Avatar of ozo
ozo
Flag of United States of America image

in windows you usually need to quote a command argument with "" instead of ''
Avatar of prgeorge3383
prgeorge3383

ASKER

tried this .... does not work
cat file.txt    |  gawk -F "";"" ""{  printf(",%s,%s,%s,%s,\n", substr($21,0,10),$99,$105,$104)}""

cat file.txt    |  gawk -F ";" ""{  printf(",%s,%s,%s,%s,\n", substr($21,0,10),$99,$105,$104)}""

thanks
ozo meant that you use
  cat file.txt    |  gawk -F ";" "{  printf(',%s,%s,%s,%s,\n', substr($21,0,10),$99,$105,$104)}"

but I guess that you then struggle with ' inside the awk script
in such unreliable systems (Windoze, cmd.exe, whatever) you better use a file for you awk commands
try
cat file.txt    |   gawk -F ";" "{  printf("",%s,%s,%s,%s,\n"", substr($21,0,10),$99,$105,$104)}"
will try the file... that is probably the best way
ASKER CERTIFIED SOLUTION
Avatar of oleggold
oleggold
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial