Shell script calling Perl function, sort and find data, write to new files
Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!
1. The problem statement, all variables and given/known data:
I must write a shell script that calls two external Perl functions--one of which sorts the data in a file, and allows the user to write it to a new file, and the other that searches for a word in a file that's entered in by the user, and then returns where the word is, or "not found" if the word is not in the file. It also can perform the sorting and writing function in the shell. It has to start by taking in a filename of a simple text file with at least 50 words as an argument and if there is none prompt the user for a filename, and if the user does not enter a filename, then throw up a usage statement and kick the user out of the program.
2. Relevant commands, code, scripts, algorithms:
File: "test003.pl"
File: "test002.pl"
File: "sideShell.sh"
File: "test.sh"
File: "file"
3. The attempts at a solution (include all code and scripts):
Script file: "testsc"
I cannot seem to get how to pass a filename as an argument into the main program, or how to call the Perl functions with this filename as the argument. I am a complete noob at both languages, and have tried reading various websites and help forums but am having trouble finding the right way to do this--pass a file into the start of the main function and pass it to the others without having to re-enter the file each time. I have been working on this for a couple days now. This thing is due Tuesday evening, and I am stuck on the find function for sure, as well as the opening file argument part.
Any help would be much appreciated!
4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
University of Minnesota (Twin Cities), Minneapolis (MN), USA, Langanki, INET 3101 (" htt p s : / / webapps - prd . oit . umn . edu /courseinfo/ viewCourseGuideTermAndSubject . do?institution=UMNTC&searchTerm=1119&searchSubject=INET&searchCatalogNumber=3101&Submit=View#3101 " sorry, but your forum will not let me post URL links until I make 5 posts so I had to put the spaces in my link, it's legitimate once you take the spaces out)
Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).
P.S. Mods: how do you want me to cite this thread here on my final hand-ins for this project? Will just pasting the URL suffice or do you want me to do a full "MLA" citation or something like that?
You only get == in bash and ksh, and even then, only in [[ ]] not [ ].
Try
instead, that should work in any shell.
---------- Post updated at 09:47 AM ---------- Previous update was at 09:45 AM ----------
You should use '$look=shift;', not '$look=<STDIN>', since you are not feeding the file into perl as text to standard input, but as a parameter. You shouldn't be asking for it either if you're feeding it into the program automatically.
I've fixed my code using your suggestions and some other things, now my code looks like this:
"shell.sh"
"sideShell.sh"
"perl001.pl"
"perl002.pl"
When I run the "perl002.pl" script with a file "text" as the argument, and I search for the word "you", it works but I guess this crazy output that looks something like this (cycled many times):
Any idea how to get it to display the number line it's on? I thought of adding a counting integer variable to the code which would increment "++" if it finds a match, but not sure if that would work right? I also would like to swap the case switch for an if loop so I can keep the shell sort function in the same shell (and not have to call a second shell), unless you know how I can put multiple lines of code in a case switch (not just one thing; I've tried to put multiple lines in a case but cannot get that to work right)?
Any idea how to get it to display the number line it's on? I thought of adding a counting integer variable to the code which would increment "++" if it finds a match, but not sure if that would work right? I also would like to swap the case switch for an if loop so I can keep the shell sort function in the same shell (and not have to call a second shell), unless you know how I can put multiple lines of code in a case switch (not just one thing; I've tried to put multiple lines in a case but cannot get that to work right)?
You already put the content lines of the file into an array, so you can use the array index to display the line number. Using an extra counter is not necessary. Please see the comments in the code below.
Last edited by MacMonster; 10-25-2011 at 12:18 AM..
Reason: Add some comments
This User Gave Thanks to MacMonster For This Post:
Hi,
I am new to shell scripting and i need to write a automation script to execute sql files. I need to check the table if it is there in system tables and need to write a function to call the .sql files.
For ex. I have a.sql,b.sql,c.sql files, where the sql file contains DELETE and INSERT... (1 Reply)
I have a function which does awk proceessing
sub mergeDescription {
system (q@awk -F'~' '
NR == FNR {
A = $1
B = $2
C = $0
next
}
{
n = split ( C, V, "~" )
if... (3 Replies)
I need to
1.Open a csv
2.Process the csv i.e. Modify 2 column in the csv.
To modify the column the value needs to be passed to a pl/sql function and the return value should be updated
For eg:
If column 2 E,then E will be passed in database function
which will return Employee.
3. Write a... (5 Replies)
Hello all,
I know this is Unix forum, but i also know that there are some experts here who can help me out with this situation;
I am loading a data file into oracle table using Perl script by calling sqlldr script.
It does not do anything, and no data is getting loaded.
Any help,... (2 Replies)
This is my function which is creating three variables based on counter & writing these variable to database by calling another function writeRecord
but only one record is getting wrote in DB.... Please advise ASAP...:confused:
function InsertFtg
{
FTGSTR=""
echo "Saurabh is GREAT $#"
let... (2 Replies)
Some Code
After Some code part is executed the control doesnt go to rvin_doxx_scrt.. and the script exits
rvin_doxx_scrt()
{
Some Code
}
if (som code)
... (4 Replies)
Hi,
I have searched the forum for the query, But i didnt find an exact answer.
I have a script(1.sh) and a c program(sample.c)
sample.c contains many function definitions.( run(), find(), add() etc).
I want to call functions in sample.c from 1.sh and use the return value in 1.sh... (3 Replies)
i have a function defined in one ksh (ksh 1)
i want to use that function in another ksh (ksh 2)
i am using
. $<directoryname>/<ksh name>
i am calling the function defined in ksh 1 in ksh 2
i want the returnstatus from the above operation
but it is not executing the function
what i... (1 Reply)