[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Getting nawk: can't open file ...   error message

Posted on 2003-03-19
3
Medium Priority
?
656 Views
Last Modified: 2013-12-26
On a remote machine I'm running a shell script that uses nawk command.
From time to time it throws the following error message
nawk: can't open file {printf("0x%8.8x %s %s\n", \
               $3, \
               user, \
               substr($2,2))
               }
 source line number 1

The exact command line is :
cat <file> | nawk -v par=$par '{printf(("0x%8.8x %s %s\n", \
               $3, \
               par, \
               substr($2,2))
               }' >> <output file>
I'm trying to reproduce the same error on the local machine but I couldn't.
I've tried to play with the parameters, permissions etc. but I wasn't able to reproduce the case when I get exactly the same  error
Does anybody know what curcumstances cause printf to return "can't open file" error???
0
Comment
Question by:eneva
  • 2
3 Comments
 
LVL 5

Accepted Solution

by:
ecw earned 2000 total points
ID: 8166726
Put $par between double-quote, because if $par contains spaces, only the first word will be part of par=$par expansion, and thus the awk program will be interpreted by awk as a filename.  ie.

  nawk -v par="$par" '{printf(("0x%8.8x %s %s\n", \
              $3, \
              par, \
              substr($2,2))
              }' >> <output file>
0
 

Author Comment

by:eneva
ID: 8167147
Thanks.
I was able to reproduce the case. Although it's still curious how could this happen when the parameter $par in this case is a user name. As far as I know the user name cannot contain blanks in Unix( and not only in Unix).
0
 
LVL 5

Expert Comment

by:ecw
ID: 8167331
True, but how are you getting the usernames?  If by some weird stroke of misfortune the username is a single word but has leading whitespace, then the stuff above will fail, trailing whitespace is ok.
0

Featured Post

[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…
Suggested Courses

590 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question