LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Awk - get a parameter from the command line (https://www.linuxquestions.org/questions/programming-9/awk-get-a-parameter-from-the-command-line-407282/)

benjalien 01-24-2006 03:27 AM

Awk - get a parameter from the command line
 
Hi everyone,

this is what I'm trying to do: I read a file in awk (do some stupid treatement to put out a win configuration file) and output some others (according to the number of lines in the first file.

I want to do this as a script (if possible only with awk), it works, but I need one more parameter to know if I have to add a "0" to a phonenumber... I just can't get any parameter or everything is getting screwed up with the filename...

here it is:
Code:

#!/bin/awk -f -v
BEGIN { FS = ";" };
{
    print ARGV[2];
    if (/#/) {
        #print "Commented line";
    }
    else {
        print "[Branding]\r\n"                        > $1".ins";
        print "CompanyName=\r\n"                        > $1".ins";
        print "[Entry]\r\n"                                > $1".ins";
        print "Entry_Name=" $1"\r\n"                > $1".ins";
        print "[Phone]\r\n"                                > $1".ins";
        print "Phone_Number="$2"\r\n"                > $1".ins";
        print "Dial_As_Is=yes\r\n"                        > $1".ins";
        print "[Server]\r\n"                                > $1".ins";
        print "Type=PPP\r\n"                                > $1".ins";
        print "SW_Compress=no\r\n"                        > $1".ins";
        print "PW_Encrypt=no\r\n"                        > $1".ins";
        print "Negociate_TCP/IP=yes\r\n"                > $1".ins";
        print "[TCP/IP]\r\n"                                > $1".ins";
        print "Specifiy_IP_Address=no\r\n"        > $1".ins";
        print "Specify_Server_Address=yes\r\n"        > $1".ins";
        print "IP_Header_Compress=yes\r\n"        > $1".ins";
        print "Gateway_On_Remote=yes\r\n"                > $1".ins";
        print "DNS_Address=0.0.0.0\r\n"                > $1".ins";
        print "DNS_Alt_Address=0.0.0.0\r\n"        > $1".ins";
        print "[Device]\r\n"                                > $1".ins";
        print "Type=modem\r\n"                        > $1".ins";
        print "[User]\r\n"                                > $1".ins";
        print "Display_Password=no\r\n"                > $1".ins";
        print "Requires_Logon=no\r\n"                > $1".ins";
        print "Name="$3"\r\n"                                > $1".ins";
        print "Password="$4"\r\n"                        > $1".ins";
        print "[Internet_Mail]\r\n"                        > $1".ins";
        print "Use_Ms_Exchange=no\r\n"                > $1".ins";
        print "[Internet_News]\r\n"                        > $1".ins";
        print "Logon_Required=0\r\n"                > $1".ins";
        print "[URL]\r\n"                                > $1".ins";
        print "Home_Page=about:blank\r\n"                > $1".ins";
        print "AutoConfig=0\r\n"                        > $1".ins";
        print "NoWelcome=1\r\n"                        > $1".ins";
        print "[ConnectionSettings]\r\n"                > $1".ins";
        print "ApplyInsToConnection="$1"\r\n"        > $1".ins";
        print "[Mail_Signature]\r\n"                > $1".ins";
        print "Use_Mail_For_News=0\r\n"                > $1".ins";
        print "Use_Signature=1\r\n"                        > $1".ins";
    }
};

Any idea anyone?

sirclif 01-24-2006 09:06 AM

in gawk, there are two system variables you are looking for:

ARGC # number of arguments given at the command line
ARGV # array of command-line arguments

i don't know for sure, but i assume they are available in awk as well.


All times are GMT -5. The time now is 03:50 AM.