tags:

views:

778

answers:

3

The problem is related to my answer here.

I cannot get the following code to work

#!/bin/bash 
wget http://www.google.com/coop/cse?cx=017685108214920485934%3Aizx6pzojwka -O CSE-spanien
awk '/^searches [1-9]* sites, including:/ { print $2 }' CSE-spanien

Example of the Error message [edited]

$./code
--2009-04-14 19:01:32--  http://www.google.com/coop/cse?cx=017685108214920485934%3Aizx6pzojwka
Resolving www.google.com... 74.125.79.103, 74.125.79.99, 74.125.79.147, ...
Connecting to www.google.com|74.125.79.103|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: `cse?cx=017685108214920485934:izx6pzojwka.6'

    [ <=>                                                                                                               ] 8,096       --.-K/s   in 0s      

2009-04-14 19:01:33 (78.0 MB/s) - `cse?cx=017685108214920485934:izx6pzojwka.6' saved [8096]

./code: line 3: -O: command not found
awk(57264) malloc: *** error for object 0x4eee0: Non-aligned pointer being freed (2)
*** set a breakpoint in malloc_error_break to debug
awk: cmd. line:1: fatal: cannot open file `/Users/Masi/Documents/test/CSE-spanien' for reading (No such file or directory)

How can you run AWK in a Bash script?

+1  A: 

Some random thoughts

  • Check you path---the one used in the script environment. Is awk named "awk" in you environemnt?
  • Consider using HERE documents for non-trivial scripts
  • Do you need to redirect the output? What about the standard error?
  • Should you capture the exit state of the previous process and do some decision making first?
  • From you error message it looks like you could use a if [ -f FileToUse ]. If you don't know for certain whee wget will put the output, you might want to force it (-O).
dmckee
+2  A: 

You're missing -O CSE-spanien at the end of your wget line. As a result, CSE-spanien doesn't exist - wget is saving it the HTML with the filename cse?cx=017685108214920485934:izx6pzojwka.2.

Samir Talwar
Thank you for you help! The problems were the option -O in wget, and the PATHs in my computer.
Masi
+1  A: 

The problem is that wget doesn't create a CSE-spanien file in the current working directory. I suggest you to check where the file is created and add full or relative path of file in your awk command. It would also be wise to test if the expected file exists (test -f CSE-spanien && awk ...)

mouviciel