awk command line arguments not taking


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk command line arguments not taking
# 1  
Old 03-14-2015
awk command line arguments not taking

# more minusf.awk

Code:
#!/bin/awk -f
BEGIN {
        FS=":";
}
{
        if ( $2 == "" ) {
                print $1 ": no password!";
        }
}



Code:
# ./minusf.awk aa aa aa aa
awk: can't open aa


Please help

Last edited by Scrutinizer; 03-14-2015 at 02:33 PM.. Reason: icode to code tags
# 2  
Old 03-14-2015
Are you in the correct directory ?
# 3  
Old 03-14-2015
Please use code tags for multiline output, not icode tags.
As i undertand awk so far, i'd assume 'aa aa aa aa' is taken as a list of input files, rather than a stream as you expect.

Hope this helps and thank you.
# 4  
Old 03-14-2015
Make use of these variables

Code:
  
       Gawk's built-in variables are:

       ARGC        The  number  of command line arguments (does not include options to gawk


       ARGIND      The index in ARGV

       ARGV        Array of command line arguments.  The array is indexed from 0 to ARGC
                   cally changing the contents of ARGV can control the files used for data.

Example
Code:
akshay@Aix:/tmp$ cat test.awk 
BEGIN{
	for(i=1; i<ARGC; i++)
	  printf("ARG[%d] = %s\n",i,ARGV[i])
}

Code:
akshay@Aix:/tmp$ awk -f test.awk user password etc etc
ARG[1] = user
ARG[2] = password
ARG[3] = etc
ARG[4] = etc

# 5  
Old 03-14-2015
Would this work (recent bash needed):
Code:
./minusf <<< "aa:aa:aa:aa"

?
# 6  
Old 03-14-2015
My understanding goes $1 $2 ... representing the commandline arguments

My understanding goes that when I use the $1 ... in the code, the values for thiese var's / parameters ($1...) should be given as arguments while running the program

and @Kumaran , I am in the correct direcorty.
@sea i'd assume 'aa aa aa aa' would be taken as a single string, also these are not the files rather just values for the parameters
@Rudic using ./minusf <<< "aa:aa:aa:aa" I have'nt got any output

However I still did not get any ouput.

Code:
# ./minusf.awk 'aa aa aa aa'
awk: can't open aa aa aa aa

# 7  
Old 03-14-2015
Quote:
Originally Posted by sri.phani
My understanding goes that when I use the $1 ... in the code, the values for thiese var's / parameters ($1...) should be given as arguments while running the program

and @Kumaran , I am in the correct direcorty.
@sea i'd assume 'aa aa aa aa' would be taken as a single string, also these are not the files rather just values for the parameters
@Rudic using ./minusf <<< "aa:aa:aa:aa" I have'nt got any output

However I still did not get any ouput.

Code:
# ./minusf.awk 'aa aa aa aa'
awk: can't open aa aa aa aa

Is this a homework assignment? Homework assignments must be posted in the Homework and Coursework Questions forum and you need to completely fill out the homework template before we can help you with your assignment.

Your understanding is incorrect. You are mixing shell command line parameter parsing with awk field parsing and coming up with something that doesn't work for either.

And, if you want your awk script to read /etc/passwd, you have to tell your awk script to read it; not just assume that awk can magically guess that that is the file you are trying to process.

Furthermore, I don't see anything in your code that makes any attempt to identify a line in the password file that will match any user you want to examine.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to pass command line arguments to awk program?

#!/bin/awk -f BEGIN { FS=":"; } { if ( $7 == "" ) { print $1 ": no password!"; } } I want to execute this program for a particular user to check for his password from the file /etc/passwd (as the input file) and the user details to be given... (1 Reply)
Discussion started by: sri.phani
1 Replies

2. UNIX for Dummies Questions & Answers

taking the output of awk command to a new file

cat doc | nawk -v da="${date}" '$23>199 {print $0 > "doc"+da+".txt"}' Every time(need to run every day) i run this, i want to a create a new file "doc_01 Aug.txt". Basically, i want to create a new file with date appended in it. The above command is creating a file with name "0".... (4 Replies)
Discussion started by: vagar11
4 Replies

3. UNIX Desktop Questions & Answers

scripts taking arguments

I am trying to write a script using commands to print a sequence of numbers. However, I can't get jot to recognize what I give it. Terri$ cat mncmd echo "m=$1" echo "n=$2" $jot $2 Terri$ ./mncmd 1 10 m=1 n=10 ./mncmd: line 3: $2: command not found I've also tried Terri$ cat... (3 Replies)
Discussion started by: justOne21
3 Replies

4. Shell Programming and Scripting

command line arguments

hi,,,, I want to create a command prompt, for example "prompt>", so my prompt need to handle commands, for example "prompt>cmd", so i want to know how to get arguments for my own commands cmd, i.e. default argc should contain arguments count and argv should point to the argument vector i.e, for... (2 Replies)
Discussion started by: vins_89
2 Replies

5. UNIX for Dummies Questions & Answers

command line arguments

hi, can someone how to accept command line arguments as a variable using in script? like: ./scriptname arguments by accept arguments, I can use it in my script? thx! (1 Reply)
Discussion started by: ikeQ
1 Replies

6. Shell Programming and Scripting

Pass command line arguments to awk

I am trying to pass max as a sommand line argument when I call awk. Made the modification in the BEGIN but it is not working I'm getting an error as below: awk: txsrx.awk:82: (FILENAME=jcd.tx FNR=4161) fatal: cannot open file `40' for reading (No such file or directory) Somehow it... (2 Replies)
Discussion started by: kristinu
2 Replies

7. Shell Programming and Scripting

using command line arguments as columns for pattern matching using awk

Hi, I wish to use a column, as inputted by a user from command line, for pattern matching. awk file: { if($1 ~ /^8/) { print $0> "temp2.csv" } } something like this, but i want '$1' to be any column as selected by the user from command line. ... (1 Reply)
Discussion started by: invinclible0009
1 Replies

8. UNIX for Dummies Questions & Answers

Command line arguments.

I am working on a script wherein i need the user to enter the Build ID for eg:the command line will show enter the build ID Now on entering the build ID it should be assigned to @ARGV. How can this be done.? (1 Reply)
Discussion started by: Varghese
1 Replies

9. Shell Programming and Scripting

command line arguments

-------------------------------------------------------------------------------- I have this while loop and at the end I am trying to get it to tell me the last argument I entered. And with it like this all I get is the sentence with no value for $1. Now I tried moving done after the sentence... (1 Reply)
Discussion started by: skooly5
1 Replies

10. Programming

command line arguments

Hi How to pass multi line text as a command line argument to a program. (i.e) ./a.out hi this is sample 0 file1 where hi this is sample should be stored in argv 0 in argv and so on... (3 Replies)
Discussion started by: bankpro
3 Replies
Login or Register to Ask a Question