LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 01-05-2011, 12:53 PM   #1
smritisingh03
Member
 
Registered: Nov 2010
Posts: 43

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


Hi
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);
j=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, 06:15 PM   #2
Snark1994
Senior Member
 
Registered: Sep 2010
Location: Wales, UK
Distribution: Arch
Posts: 1,632
Blog Entries: 3

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

Code:
#!/bin/bash

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, 11:39 PM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,250

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
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:
Code:
#!/usr/bin/awk -f

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

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

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


Reply


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


All times are GMT -5. The time now is 04:54 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration