Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 01-05-2011, 11:53 AM   #1
Registered: Nov 2010
Posts: 43

Rep: Reputation: 0
Unhappy how to pass argument from command prompt

when I am running the script below,it performs on whatever logfile u type ,i.e, ./scriptname logfilename

But how do I convert it into a function and then call it from another script.I mean how do I prompt the user to enter a logname and then capture the name in the function and when calling this function from another script how do I pass the parameter.

please help and thankyou so much in advance!!!

my script looks like:

awk ' {

if (index ( $0, ". . exporting table") >0 || index ($0, ". . exporting partition") >0) #searches for the pattern in string


if ($4 != "partition"){ #$4 is either table or a partition
i=$6; #$6 is the number of rows stored in variable i here

if (table_flag ==0 && table_name ==temp_table_name){ # checking the flag

printf table_name > "logcountOP";
printf " " > "logcountOP";
print j > "logcountOP";

table_name = $5; #$5 has the name of the table from which the rows have been imported
temp_table_name = table_name;
table_flag =1; #setting the flag to 1


if ($4 == "partition") {

i=i+$6; #summing up the rows in partitioned tables
printf("value of i in first: %d\n",i);
table_flag=0; #setting flag to 0

if (table_flag !=0 && $6 !=""){

printf table_name >> "logcountOP";
printf " " >> "logcountOP";
print i >> "logcountOP";


} ' < $1
Old 01-05-2011, 05:15 PM   #2
Senior Member
Registered: Sep 2010
Location: Wales, UK
Distribution: Arch
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
If the script you typed above is /usr/bin/myScript, then you should just be able to use:


read logfilename
myScript $logfilename
This reads in one word to the variable logfilename, then runs your script with the same variable as its parameter. Was this what you were looking for?

All the best,
Old 01-05-2011, 10:39 PM   #3
LQ Guru
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,529

Rep: Reputation: 2896Reputation: 2896Reputation: 2896Reputation: 2896Reputation: 2896Reputation: 2896Reputation: 2896Reputation: 2896Reputation: 2896Reputation: 2896Reputation: 2896
Seeing as this is simply an awk script in a bash wrapper, just get rid of bash altogether and ask for log name in the BEGIN:
#!/usr/bin/awk -f

    printf "Enter name of logfile: "
    getline logfile < "-"

    while(getline < logfile){
        <your stuff here>
Old 01-08-2011, 09:18 AM   #4
Registered: Nov 2010
Posts: 43

Original Poster
Rep: Reputation: 0
Thank uoy so much!!!it works.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 do I pass command to gnome-terminal as an argument? crasywolf Linux - Newbie 5 05-11-2010 09:00 AM
How To pass argument in Expect command? jprathap Linux - Newbie 3 08-27-2009 04:58 PM
Possible to pass an argument from one shell env to another? ne00 Programming 4 04-15-2009 09:19 PM
[SOLVED] pass file-name as command line argument vikas027 Programming 2 10-14-2008 11:52 PM
How to pass an argument to DHCPCD ? shazam75 Linux - Networking 3 02-27-2005 10:34 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:13 AM.

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