LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-24-2006, 03:27 AM   #1
benjalien
Member
 
Registered: Aug 2003
Location: Belgium
Distribution: Debian (i686/ppc/amd64)
Posts: 86

Rep: Reputation: 15
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?
 
Old 01-24-2006, 09:06 AM   #2
sirclif
Member
 
Registered: Sep 2004
Location: south texas
Distribution: fedora core 3,4; gentoo
Posts: 192

Rep: Reputation: 30
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to pass command-line parameter to shell script? Kropotkin Linux - Newbie 12 07-25-2011 09:24 AM
Awk command-line arguments lowpro2k3 Programming 1 03-28-2005 09:09 PM
Sed/Awk command help needed. farmerjoe Programming 3 03-02-2005 11:13 AM
Deleting a line with gawk/awk caps_phisto Linux - General 4 11-06-2004 02:31 PM
cut / awk command?? Sammy2ooo Linux - Newbie 1 05-27-2003 05:46 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:40 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration