Solved awk in Windows, how to redirect output

November 10, 2011 at 12:30:26
Specs: Win7, 4gb
Hi, I'm a newbie on awk. I have a file (BB-list.txt) with the following in it:
# Number of URL page elements = 0
# Total Bytes Downloaded = 29482988 byte(s)
# Previously Cached Bytes = 2552799 byte(s)
# Waiting Time (39% of total) = 58319 msec(s)
# System Time (61% of total) = 91434 msec(s)
# TOTAL Time (100% of total) = 149753 msec(s)

Using gawk I have been able to print (extract) the downloaded bytes only, which is what I need ( 29482988).
gawk "/Total Bytes Downloaded/, /byte/ {print $6}" C:\Users\me\Desktop\gawk\BBS-list.txt

My question is how can I redirect the output to a file called testFile1? I have tried the following:
gawk "/Total Bytes Downloaded/, /byte/ {print $6 > "testFile1"}" C:\Users\me\Desktop\gawk\BBS-list.txt

The above script gives me the following error:
gawk: (FILENAME=C:\Users\me\Desktop\gawk\BBS-list.txt FNR=1395) fatal: expression for `>' redirection has null string value

Any help would be appreciated.

thanks,
REMGU

Thanks,
REMGU


See More: awk in Windows, how to redirect output

Report •

#1
November 10, 2011 at 13:10:02
✔ Best Answer
gawk "/Total Bytes Downloaded/, /byte/ {print $6}" C:\Users\me\Desktop\gawk\BBS-list.txt  > testFile1


Report •

#2
November 10, 2011 at 13:18:45
IVO, that was my very first thought but when I ran the script nothing occured. No error, no showing where the file was created, nothing. I then read in the awk manual that:

"Redirections in awk are written just like redirections in shell commands, except that they are written inside the awk program."

The "program" being the stuff in the script in between quotes.

Thanks,
REMGU


Report •

#3
November 10, 2011 at 13:23:45
IVO, never mind. Thanks, I tried it again and it did work. Not sure what I was doing wrong the first time and what the manual is referring to then.

Thanks,
REMGU


Report •

Related Solutions

#4
November 10, 2011 at 13:28:01
Sorry try to remove double quotes around testFile1, i.e.

gawk "/Total Bytes Downloaded/, /byte/ {print $6 > testFile1}" C:\Users\me\Desktop\gawk\BBS-list.txt 


Report •

#5
November 10, 2011 at 13:30:35
Nah, it doesn't like it when I take them out. For now your suggestion works, although it's not what the manual states should be but oh well. Thanks again.

Thanks,
REMGU


Report •

Ask Question