Script gurus please help me out with this script. when i am running the script in vi i am getting the below error
Running the script in vi
These two are my inputs But when I am, running the script in this its working but not giving the require o/p Output But I want to be my output like this in the same line and for /tmp/p2 it will run only one time.
Thanks in advance
Regards Nirjhar
Last edited by zxmaus; 08-14-2011 at 11:58 PM..
Reason: added code tags
I'm confused by what it is you mean when you say "trying to run from vi." Using the :! command vi command? Unfortunately I cannot explain the error you are getting; your script runs without error for me both under Kshell and bash.
Your undesired output is a result of your logic. It appears based on your p1 and p2 files (thanks for adding their contents) that you want line 1 from each file to be matched and used, then line 2 from each, etc. The nested loops in your script will take line 1 from the p1 file and match it with all lines in p2, then take line 2 from p1 and match it with all lines from p2 and so forth. Giving you way more output sets than it seems you desire.
The other problem is that you are using echo to print partial lines and that will always insert a new line. You can use an option to echo to suppress the newline, but that's not always portable, so I recommend you use printf instead. In this case, after the script is corrected, you only need one printf anyway, so you could use echo.
1.I am putting all my code in the file by using vi editor and getting "syntax related error"
2.I am new to shell scripting you have made this code by using array,
If you have time would you please explain the body of your code.
what is typeset in this code. while compiling this script i am getting below error.
Regards
Nirjhar
Last edited by zxmaus; 08-14-2011 at 11:59 PM..
Reason: added code tags
1.I am putting all my code in the file by using vi editor and getting "syntax related error"
Ok, so you're getting the error after you save the file and when you try to execute it? That makes a bit more sense.
Quote:
2.I am new to shell scripting you have made this code by using array,
If you have time would you please explain the body of your code.
what is typeset in this code. while compiling this script i am getting below error.
bash-3.00# sh /tmp/t1
/tmp/t1: typeset: not found
/tmp/t1: typeset: not found
/tmp/t1: syntax error at line 9: `i=$' unexpected
The typeset -a name defines the variable name as an indexed array. You're getting the typeset errors because you are using the bourne shell (sh) instead of bash or ksh. If you enter the command bash /tmp/t1 you shouldn't get the errors.
Further, if you make your script executable, and have the proper #! statement as the first line, you will only need to type the filename of the script on the command line.
The very first line in your script file (no blank lines before it) should be this:
That line will cause the process that opens your script for execution to execute it using bash. It is a way of ensuring that bash is used, even if the shell you use for your comand line isn't bash.
I hope that makes some sense.
The logic of the code I posted is this:
1) Read all records from the p1 file into an array named p1v (p1 values). If there are 4 records in the file there will be 4 values in p1v (p1v[0], piv[1]... p1v[4]).
2) Do the same for p2 -- read all values into p2v.
3) After reading values into p2v, the variable i will contain the number of records read.
4) finally, for each name/number pair entered, loop from 0 to i and print the desired lines using the corresponding p1v and p2v values.
I have tried to write one more code here for the same output by taking all the inputs in one file.
Please check
My input file
Code is My output
The only problem is this when i am entering the input "10c" the ourput should be 10c but it comes only 10 so where is the "c" i am not able to find it.
and my for loop is also not working same error repeating that syntax is not right.
thanks in advance.
Regards
Nirjhar
Last edited by zxmaus; 08-15-2011 at 12:00 AM..
Reason: added code tags
I have tried to write one more code here for the same output by taking all the inputs in one file.
This seems much better to me.
Quote:
The looping issue might be that you either need to initialise i to 0, or change the conditional to i <= N.
You are seeing the 'c' dropped because of the way you are quoting your awk. I personally believe that it's never good form to open and close quotes to include shell variables in your awk. This is the way I would write it:
Notice that there is no need for using cat as awk is capable of reading directly from the file. Also, not having the single quotes broken, you don't run into any of the issues that you were seeing before.
When you ran your script the print statement ended up looking like this after expansion of the shell variables:
You should notice that the 10c is unquoted, so awk will interpret it as a number (awk silently drops the trailing letters) and that is why it was printing 10 instead.
I'm new to utilities like socat and netcat and I'm not clear if they will do what I need.
I have a "compileDeployStartWebServer.sh" script and a "StartBrowser.sh" script that are started by emacs/elisp at the same time in two different processes.
I'm using Cygwin bash on Windows 10.
My... (3 Replies)
Hello all,
I am facing a weird issue while executing a code below -
#!/bin/bash
cd /wload/baot/home/baotasa0/sandboxes_finance/ext_ukba_bde/pset
sh UKBA_publish.sh UKBA 28082015 3
if
then
echo "Param file conversion for all the areas are completed, please check in your home directory"... (2 Replies)
I am trying to call a script(callingscript.sh) from a master script(masterscript.sh) to get string type value from calling script to master script. I have used scripts mentioned below.
#masterscript.sh
./callingscript.sh
echo $fileExist
#callingscript.sh
echo "The script is called"... (2 Replies)
I am using blow script :--
#!/bin/bash
FIND=$(ps -elf | grep "snmp_trap.sh" | grep -v grep) #check snmp_trap.sh is running or not
if
then
# echo "process found"
exit 0;
else
echo "process not found"
exec /home/Ketan_r /snmp_trap.sh 2>&1 & disown -h ... (1 Reply)
Hi guys
I have a shell script that executes sql statemets and sends the output to a file.the script takes in parameters executes sql and sends the result to an output file.
#!/bin/sh
echo " $2 $3 $4 $5 $6 $7
isql -w400 -U$2 -S$5 -P$3 << xxx
use $4
go
print"**Changes to the table... (0 Replies)