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

Posted on 2003-03-19
Medium Priority
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, \
 source line number 1

The exact command line is :
cat <file> | nawk -v par=$par '{printf(("0x%8.8x %s %s\n", \
               $3, \
               par, \
               }' >> <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???
Question by:eneva
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Accepted Solution

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, \
              }' >> <output file>

Author Comment

ID: 8167147
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).

Expert Comment

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.

Featured Post

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

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

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Suggested Courses
Course of the Month14 days, 9 hours left to enroll

771 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