KSH Script to Execute command from specific column in file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting KSH Script to Execute command from specific column in file
# 1  
Old 08-23-2011
Error KSH Script to Execute command from specific column in file

Hi Unix Experts,Team

I have a file (say comand_file.prm), The file has a command specified in column 6 (say "./execute_script.sh"). I want to execute this command in my script.
I am writing a KSH script to achieve this. Could you please assist me with this.
# 2  
Old 08-23-2011
Code:
awk '{print $6}' command_file.prm | sh

# 3  
Old 08-23-2011
Bug

Thanks Yazu,
Is there any way to pass positional parameters to the command specified in column.

e.g If I need to pass ${ip_address} and ${host_name} variables to execute_script.sh, how can I get this.
# 4  
Old 08-23-2011
Be more specific. It depends on how your script gets arguments and how your variables get values, and whether they are the same for every command or not.
# 5  
Old 08-23-2011
Hi Yazu,
To be specific, below are two requirements.

1. In some cases I want to pass the variable values along with the command mentioned in column.

Example :- ./execute_script.sh prm1 prm2

2.If the executable mentioned in column is interactive, I want to pass inputs interactively.

Example : ./jdk-6u20-linux-i586.bin ( this will begin installation and ask for instructions during execution, like accept license agreement (yes or no) :

Please advise if this can be achieved,

Regards,
Jeevan
# 6  
Old 08-23-2011
How you will decide, whether the executable "defined" in column is interactive?

I don't think there is any specific way to find whether an exe is a interactive or not!!!
# 7  
Old 08-31-2011
Hi All,

The Problem is resolved. I made it this way
Code:
echo "$line |cut -d, -f6" $PRM1 $PRM2 |sh


Last edited by Franklin52; 08-31-2011 at 04:16 AM.. Reason: Please use code tags for code and data samples, thank you
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Modifying bash script to take each line in a file and execute command

I need to modify a bash script to to take each line in a file and execute command. I currently have this: #!/bin/bash if ; then echo "Lipsa IP"; exit; fi i=1 ip=$1 while ; do if ; then rand=`head -$i pass_file | tail -1` user=`echo $rand | awk '{print $1}'` pass=`echo $rand | awk '{print $2}'`... (3 Replies)
Discussion started by: galford
3 Replies

2. Shell Programming and Scripting

sed working on command line but file unchanged when execute with Shell script

I have a simple task to replace unix line feed end of line characters with carriage returns. When I run the following “change file in place” sed instruction from the command line all the Line feeds are successfully replaced with Carriage returns. sed -i 's/$/\r/' lf_file.txt But that same... (1 Reply)
Discussion started by: hawkman2k
1 Replies

3. Shell Programming and Scripting

Overwrite specific column in xml file with the specific column from adjacent line

I have an xml file dumped from rrd file, that I want to "patch" so the xml file doesn't contain any blank hole in the resulting graph of the rrd file. Here is the file. <!-- 2015-10-12 14:00:00 WIB / 1444633200 --> <row><v> 4.0419731265e+07 </v><v> 4.5045912770e+06... (2 Replies)
Discussion started by: rk4k
2 Replies

4. Shell Programming and Scripting

find specific file names and execute a command depending on file's name

Hi, As a newbie, I'm desperate ro make my shell script work. I'd like a script which checks all the files in a directory, check the file name, if the file name ends with "extracted", store it in a variable, if it has a suffix of ".roi" stores in another variable. I'm going to use these two... (3 Replies)
Discussion started by: armando110
3 Replies

5. Shell Programming and Scripting

how to execute ksh simple shell script without creating .sh file

please help me to execute a simple shell script like for i in `ls echo $i done . i dont want to create a new sh file to execute it. Can i just type and execute it ? because I always this kind of simple for loops . Please help . Thanks (7 Replies)
Discussion started by: Sooraj_Linux
7 Replies

6. Shell Programming and Scripting

How can I execute another shell from my ksh script?

I am newbie in UNIX, so please excuse me for the stupid question.:) Here is a problem: I created ksh script where the part of the functionality include an opening of a second session with another shell process "runrep"(runrep is a custom reporting shell designed by Advent Geneva). When I run my... (3 Replies)
Discussion started by: alexstar
3 Replies

7. Shell Programming and Scripting

Execute command on first column (filename) retrieved from a file

Hi, I have a file abcd.txt which in turn contains 20 file names as column 1. Now I want to run a command "ct co -nc" / "cp" / "mv" on each of these $1 column content i.e. on each of the 20 file names. How can do this using a script so that I need not run the same command 20 times... (13 Replies)
Discussion started by: royzlife
13 Replies

8. Shell Programming and Scripting

Assigning a specific format to a specific column in a text file using awk and printf

Hi, I have the following text file: 8 T1mapping_flip02 ok 128 108 30 1 665000-000008-000001.dcm 9 T1mapping_flip05 ok 128 108 30 1 665000-000009-000001.dcm 10 T1mapping_flip10 ok 128 108 30 1 665000-000010-000001.dcm 11 T1mapping_flip15 ok 128 108 30... (2 Replies)
Discussion started by: goodbenito
2 Replies

9. Shell Programming and Scripting

ksh execute command containing double quotes

How do I execute a command containing a double quote ? I pass a variable to grep that contains spaces, so I need to quote it, but it does not work. #!/usr/bin/ksh set -x txt='"next to"' cmd="grep $txt ~dpearso5/file2" echo $cmd $cmd This is the error I get: + grep "next to"... (1 Reply)
Discussion started by: pearson05
1 Replies
Login or Register to Ask a Question