Change all single-quotes to double-quotes in your shell script, like so -
Code:
$
$
$ cat word_extractor_script.sh
perl -p -e "s/^.*?$1/$2/" cleanme > CleanerExtract
sed "s/^/$1 /g" CleanerExtract > CleanerExtract1
sed -n "/$2/p" CleanerExtract1 > CleanerExtract2
sed G CleanerExtract2 > CleanerExtract3
sed -e "s/.*$1//" -e "s/$2.*//" CleanerExtract3 > CleanerExtract4
sed "/^.\{1000\}/d" CleanerExtract4 > OutputShorter_$1_$2
rm CleanerExtract
rm CleanerExtract1
rm CleanerExtract2
rm CleanerExtract3
rm CleanerExtract4
$
$
It should work thereafter -
Code:
$
$ # show the contents of file "cleanme"
$ cat cleanme
There is a cat next to a dog. The dog is next to the cat. The elephant is behind the dog but under the cat which is to one side of the elephant and underneath the dog.
$
$ # show the contents of script "word_extractor_script.sh"
$ cat word_extractor_script.sh
perl -p -e "s/^.*?$1/$2/" cleanme > CleanerExtract
sed "s/^/$1 /g" CleanerExtract > CleanerExtract1
sed -n "/$2/p" CleanerExtract1 > CleanerExtract2
sed G CleanerExtract2 > CleanerExtract3
sed -e "s/.*$1//" -e "s/$2.*//" CleanerExtract3 > CleanerExtract4
sed "/^.\{1000\}/d" CleanerExtract4 > OutputShorter_$1_$2
rm CleanerExtract
rm CleanerExtract1
rm CleanerExtract2
rm CleanerExtract3
rm CleanerExtract4
$
$ # execute the script passing "cat" and "dog" as parameters
$ ./word_extractor_script.sh cat dog
$
$ # show the contents of "OutputShorter_cat_dog"
$ cat OutputShorter_cat_dog
which is to one side of the elephant and underneath the
$
$
In any case, are you trying to do this ?
Code:
$
$ perl -plne 's/^.*cat(.*?)dog.*$/$1/' cleanme
which is to one side of the elephant and underneath the
$
You don't need so many calls to sed in such a case.
tyler_durden
This User Gave Thanks to durden_tyler For This Post:
I have created a script "myscript.sh"
I need to run this script with diffrent parameters.
The parameters are stored in a file myparam.txt.
I need to run myscript.sh script for every parameter supplied in myparam.txt.
Example:
If myparam.txt contains following lines:
param1
param2
param3... (3 Replies)
hi,
i am passing around 14 parameters for a script
a=$1
b=$2
c=$3
d=$4
e=$5
f=$6
g=$7
h=$8
i=\"${9}\"
shift
j=\"${1}\"
still for j it is displaying the 1st parameter value..how to make it take the 10th parameter (2 Replies)
Hi,
The below script is working fine
awk1.sh
=======
awk BEGIN { FS="|" } FNR==NR { f1=$2; next } $1 in f1 && $2 =="xx" && $1 == "DAILY_JOB" {print $3}
awk -f awk1.sh a.txt b.txt--Its working fine .
When passing parameters its not working .Any help it should be appereciated.
... (4 Replies)
I am writing a script that should read the csv file and pass the values in the file as parameters
to the script. The csv file looks like this:
TEST_1,20110221
TEST_2,20110220
TEST_3,20110218,20110219
Currently this is how i am running the script
./test.sh <param1> <date>
Ex: ./test.sh... (6 Replies)
Hi All,
I am new to shell scripting required some help in passing the parameter value to the shell script.
I am writing a shell script, in the script I have created two functions as below.
first function
get_trend_ids () {
Here I am connecting to the database and getting all the... (3 Replies)
Hi All,
I have written a shell script and the script is working fine, I am passing my MIT_ID(NUMBER VALUE) to the shell script from the command prompt and my script is executing as expected.
Now I have to pass all the MIT_ID's from a .txt file to the shell script,as I am automating this I... (6 Replies)
how can i make a script to run only when parameters are given,
if parameters are not given it should through an error , saying "please enter a parameter"
for ex: i want a find command to run only when the parameters are given (4 Replies)
we are using following script to execute stored procedue. The problem is run_pmcmd.ksh script is using $*
parameter which is not taking in account 'Men Shirt' parameter which includes spaces.
1. Step 1
run_pmcmd.ksh CONVERT_TEST
script for run_pmcmd.ksh
/u01/$(whoami)/run_pmcmd.ksh... (11 Replies)
I have a script that uses more than one parameter. It looks like this:
for i in `cat /tmp/listofpolicies`;
do
for x in $(cat /tmp/lst |sed 's/^/\/usr\/openv\/netbackup\/db\/class\//g');
do /usr/openv/netbackup/bin/admincmd/bpplinclude $i -delete -f $x;done;done
The problem is that the... (3 Replies)
Hello Experts,
I have a requirement to pass some parameters to Linux cron tab.
For ex: My default cron entry looks like this as below:
-------------------------------
55 10 * * --... (7 Replies)
Discussion started by: MaheshChaudhari
7 Replies
LEARN ABOUT REDHAT
pidof
PIDOF(8) Linux System Administrator's Manual PIDOF(8)NAME
pidof -- find the process ID of a running program.
SYNOPSIS
pidof [-s] [-x] [-o omitpid] [-o omitpid..] program [program..]
DESCRIPTION
Pidof finds the process id's (pids) of the named programs. It prints those id's on the standard output. This program is on some systems
used in run-level change scripts, especially when the system has a System-V like rc structure. In that case these scripts are located in
/etc/rc?.d, where ? is the runlevel. If the system has a start-stop-daemon (8) program that should be used instead.
OPTIONS -s Single shot - this instructs the program to only return one pid.
-x Scripts too - this causes the program to also return process id's of shells running the named scripts.
-o Tells pidof to omit processes with that process id. The special pid %PPID can be used to name the parent process of the pidof pro-
gram, in other words the calling shell or shell script.
NOTES
pidof is simply a (symbolic) link to the killall5 program, which should also be located in /sbin.
When pidof is invoked with a full pathname to the program it should find the pid of, it is reasonably safe. Otherwise it is possible that
it returns pids of running programs that happen to have the same name as the program you're after but are actually other programs.
SEE ALSO shutdown(8), init(8), halt(8), reboot(8)AUTHOR
Miquel van Smoorenburg, miquels@cistron.nl
01 Sep 1998 PIDOF(8)