0

Hi I have 2 files in my working directory. One is a simple file given by:

$ cat file2 
START 
Unix 
Linux 
START 
Solaris 
Aix 
SCO

And I have a 6000 line xml file called dblp_1_76007.xml.

When I do

awk '/START/{x="F"++i;}{print > x;}' file2

it seems to work perfectly fine but if I change the filename to the xml that is when I change it to:

awk '/START/{x="F"++i;}{print > x;}' dblp_1_76007.xml

I get the following error message:

awk: cannot open "" for output (No such file or directory)

I was originally trying to do

awk '/<www/{x="F"++i;}{print > x;}' dblp_1_76007.xml

to split each line starting with www in the xml and this also gives me the same error message.

Why do I get this error?

  • If you find yourself awking XML quite often, there's special tools for that, for example XMLgawk. – sr_ Mar 11 '14 at 8:15
3

You need an initial value for x

awk -v x=F0 '/<www/{x="F"++i};{print > x}' dblp_1_76007.xml

or only start outputting at the first www:

awk '/<www/ {x="F"++i}; i > 0 {print > x}' dblp_1_76007.xml
  • Thanks! I understood the problem. Since file2 had 'START' as the first word F1 was getting created and the command ran without any problem. But that was not the case with my XML. Thanks again for the help :) – Yathi Mar 11 '14 at 7:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.