Read Parameters from one file and make a script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Read Parameters from one file and make a script
# 1  
Old 07-22-2013
Read Parameters from one file and make a script

Hi Friends,

I have the following input parameters file

Code:
name
input
err1
out1
1
40G
DET
sylamer
dir1
dir2
123456

I want to make the following script

Code:
#!/bin/bash
#
# Name: name
# Task: name
#
#$ -N name
#$ -e input/err1.log
#$ -o input/out1.log
#$ -pe threaded 1
#$ -l h_vmem=40G

LD_LIBRARY_PATH="/usr/lib64/"

export LD_LIBRARY_PATH

cd input

mkdir input/DET/

mkdir input/sylamer/

mkdir input/DET/dir1_vs_dir2

mkdir input/sylamer/dir1_vs_dir2

myprogram.sh -i 123456 -o input/DET/dir1_vs_dir2 -1 input/dir1 -2 input/dir2

cd input/sylamer/dir1_vs_dir2

R CMD BATCH --no-save --no-restore "--args ref=\"mmu\" DETDIR=\"input/DET/dir1_vs_dir2\" outName=\"dir1_vs_dir2\" UCSCLink=\"http://test.com?id=123456\"" myprogram2.sh

So, the order of parameters u see in the input file are coming in the same order in the output too. Please don't hesitate to reply if you have any questions or suggestions on how to deal with. Thanks in advance.
# 2  
Old 07-22-2013
I'm sure I don't understand your request. The nearest guess I have is: you have a skeleton script with some placeholders that you then fill in/replace with data from another file. That you could do with an awk script... read in the data, and then read & edit the skeleton script.
# 3  
Old 07-22-2013
Quote:
Originally Posted by RudiC
I'm sure I don't understand your request. The nearest guess I have is: you have a skeleton script with some placeholders that you then fill in/replace with data from another file. That you could do with an awk script... read in the data, and then read & edit the skeleton script.
@Rudic, thanks for the response.

Your guess is right. I have my input and I want to make the output script by placing the input content at certain places. But, I have never done such complex replacement tasks. Any other starting points?
# 4  
Old 07-26-2013
I'm not sure that modifying a script is a good choice. Why don't you make your parameter file a variable definition file like
Code:
var1=name
var2=input
var3=err1
... etc.

, source it in your script and put the respective variables at the respective places:
Code:
mkdir $var2/$var7

?
# 5  
Old 07-27-2013
If you're always going to expect the same order/variables/naming conventions/etc you can extract the properties of your configuration file easy enough with grep & awk. You could probably use just awk, but, here's the easiest way.

Code:
#properties.prop
CDDIR::input

-----------
#Script
PROP_CDDIR=$(grep CDDIR properties.prop | awk"::" '{print $2}')
cd $PROP_CDDIR

Allows a person to do some very interesting dynamic coding. Smilie
# 6  
Old 07-27-2013
check this.. if it ok for you.

Code:
i=1
while read line
do

	var$i=$line
	i=`expr $i + 1`

done < inputfile.txt
echo "==========================="
echo "creating the shell script"
echo "==========================="

echo "#!/bin/bash" > shellscript.sh
echo "#" >> shellscript.sh
echo "# Name: $var1" >> shellscript.sh
echo "# Task: $var1" >> shellscript.sh
echo "#" >> shellscript.sh
echo "#$ -N $var1"	>> shellscript.sh			
echo "#$ -e $var2/$var3.log"	>> shellscript.sh				
echo "#$ -o $var2/$var4.log"	>> shellscript.sh				
echo "#$ -pe threaded $var5"	>> shellscript.sh		
echo "#$ -l h_vmem=$var6"	>> shellscript.sh		
echo "" >> shellscript.sh
echo "LD_LIBRARY_PATH="/usr/lib64/" >> shellscript.sh
echo ""  >> shellscript.sh
echo "export LD_LIBRARY_PATH" >> shellscript.sh
echo ""  >> shellscript.sh
echo "cd $var2"	>> shellscript.sh		
echo ""   >> shellscript.sh
echo "mkdir $var2/$var7/"	>> shellscript.sh		
echo ""  >> shellscript.sh
echo "mkdir $var2/$var8/"  >> shellscript.sh			
echo ""  >> shellscript.sh
echo "mkdir $var2/$var7/$var9_vs_$var10"  >> shellscript.sh	
echo ""  >> shellscript.sh
echo "mkdir $var2/$var8/$var9_vs_$var10" >> shellscript.sh	
echo ""  >> shellscript.sh
echo "myprogram.sh -i $var11 -o $var2/$var7/$var9_vs_$var10 -$var5 $var2/$var9 -2 $var2/$var10" >> shellscript.sh   
echo ""  >> shellscript.sh
echo "cd $var2/$var8/$var9_vs_$var10"  >> shellscript.sh		
echo ""   >> shellscript.sh
echo "R CMD BATCH --no-save --no-restore "--args ref=\"mmu\" $var7DIR=\"$var2/$var7/$var9_vs_$var10\" outName=\"$var9_vs_$var10\" UCSCLink=\"http://test.com?id=$var11\"" myprogram2.sh >> shellscript.sh


you script that will be created is shellscript.sh
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to make a loop to read the input from a file part by part?

Hi All, We've a VDI infrastructure in AWS (AWS workspaces) and we're planning to automate the process of provisioning workspaces. Instead of going to GUI console, and launching workspaces by selecting individual users is little time consuming. Thus, I want to create them in bunches from AWS CLI... (6 Replies)
Discussion started by: arun_adm
6 Replies

2. Shell Programming and Scripting

Read csv file, convert the data and make one text file in UNIX shell scripting

I have input data looks like this which is a part of a csv file 7,1265,76548,"0102:04" 8,1266,76545,"0112:04" I need to make the output data should look like this and the output data will be part of text file: 7|1265000 |7654899 |A| 8|12660000 |76545999 |B| The logic behind the... (6 Replies)
Discussion started by: RJG
6 Replies

3. Shell Programming and Scripting

Shell Script to Dynamically Extract file content based on Parameters from a pdf file

Hi Guru's, I am new to shell scripting. I have a unique requirement: The system generates a single pdf(/tmp/ABC.pdf) file with Invoices for Multiple Customers, the format is something like this: Page1 >> Customer 1 >>Invoice1 + invoice 2 >> Page1 end Page2 >> Customer 2 >>Invoice 3 + Invoice 4... (3 Replies)
Discussion started by: DIps
3 Replies

4. Shell Programming and Scripting

Loop to read parameters and stop

Hey guys, How do I make a loop that reads all the parameters en then stop when there are no parameters anymore ? Something that gives an output like this: ./Script.sh parameter1 parameter2 parameter3 parameter = parameter1 parameter = parameter2 parameter = parameter3 Thanks a lot,... (5 Replies)
Discussion started by: Miki1579
5 Replies

5. Shell Programming and Scripting

Calling sql file from shell script with parameters.

Hi, I am calling a sql file script.sql from shell script and passing few parameters also as shown below: sqlplus -S id/password @script.sql $param1 $param2 Now,In sql file I have to create a extract text file after querying oracle tables based on the parameters passed(param1,param2) as... (7 Replies)
Discussion started by: anil029
7 Replies

6. Solaris

Which file is read by kernel to set its default system kernel parameters values?

Hi gurus Could anybody tell me which file is read by kernel to set its default system kernal parameters values in solaris. Here I am not taking about /etc/system file which is used to load kernal modules or to change any default system kernal parameter value Is it /dev/kmem file or something... (1 Reply)
Discussion started by: girish.batra
1 Replies

7. Shell Programming and Scripting

Read parameters from a file

Hello all, I need to extract parameters from a file. For example, I have a file file.dat as par1 val1 par2 val2 par3 val3 I need to extract this and store val1 in par1 variable and so on. Please help. Thanks for your support. (2 Replies)
Discussion started by: cheerful
2 Replies

8. Shell Programming and Scripting

read parameters from file

Hi there, I'm wondering how I can run a script that would loop and launch a command that would take as parameter every line in a file one by one. For example, say I want to remove a list of files: ~$ cat filestoremove foo bar ~$ cat myscript for file in filestoremove; do rm $file... (2 Replies)
Discussion started by: chebarbudo
2 Replies

9. Shell Programming and Scripting

(Problem) Script with Parameters file

Hello, this is my first post, and.... obviusly, i have a problem, i have this script: #!/bin/sh . /tmp/variables ... ... DESTINATION=`hostname`_DESTINATION ... and the /tmp/variables has: #!/bin/sh aix53_DESTINATION="/temporal/`hostname`.mksysb.`date +\%d\%m\%y`" ** The problem is... (2 Replies)
Discussion started by: pelado
2 Replies

10. Shell Programming and Scripting

How to make parameters optional?

Hi, I am trying to call a function inside a shell script. Is there a way in which I can make the parameters options in the call? Please help me with this. Thanks!!! (2 Replies)
Discussion started by: neeto
2 Replies
Login or Register to Ask a Question