passing variable to another file and replacing


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting passing variable to another file and replacing
# 1  
Old 11-29-2011
passing variable to another file and replacing

Hi all,

I have a script in file1 which gets input from the user say variable "TYPE". This variable is present in the other file2. I want to replace the variable in the file2 with the value given by the user and print the file. How can I achieve this task?

file1
code
echo "Give the type"
read TYPE


file two
code
echo "$TYPE"


input
newfile

expected output when I cat the file2

newfile








Thanks in advance
Ananth
# 2  
Old 11-29-2011
Try parsing the value to the second file..

Code:
file1.sh:
#!/bin/sh
echo "Give the type"
read TYPE
./file2.sh	${TYPE}


file2.sh
#!/bin/sh
echo "$1"

# 3  
Old 11-29-2011
Just write after read statement
/usr/bin/sed 's/$TYPE/'$TYPE'/' file2 > file3 and then you can [cat]/print the file.
This User Gave Thanks to CaapAjayShukla For This Post:
# 4  
Old 11-29-2011
Shukla, Excellent. It worked out. Thanks.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Passing a file name to a variable

Below is the command mv AP_FLEXCUBE_INTERFACE10.txt FTPYMNTE_`date "+%Y%m%d%H%M%S" | tr '' ''`.TXT it is changing the file name to a different name according to time stamp dynamically. I want to capture that dynamic file name present in the directory to a variable . After that i want to... (6 Replies)
Discussion started by: sujit das
6 Replies

2. Shell Programming and Scripting

Passing Shell variable from file to another command

Hi all, I have a file looks like AAAA 111 BBBB 222 CCCC 333 need to pass variable value like var1=AAAA and var2=111 to another command for three times with next values. stuck over here cat file | while read line do export var1=`awk '{print $1}'` echo $var1 export var2=`cat file... (3 Replies)
Discussion started by: rakeshtomar82
3 Replies

3. Shell Programming and Scripting

Passing variable from file to Oracle

cat a1 scott robert tom test script : #!/usr/bin/ksh for NAME in `cat a1` do VALUE=`sqlplus -silent "nobody/bobody01@testq" <<END set pagesize 0 feedback off verify off heading off echo off select username from dba_users where username=upper('$NAME'); END` if ; then echo... (3 Replies)
Discussion started by: jhonnyrip
3 Replies

4. Shell Programming and Scripting

Passing variable from file to sql from script

Hi Friend, I have one file in which some number are mentioned and number of lines are vary every time And i need to pass that number to my sql command from script. Suppose i have file acc.txt 45456546456 45464564565 67854353454 67657612132 Number of records are vary every time.... (20 Replies)
Discussion started by: pallvi_mahajan
20 Replies

5. Shell Programming and Scripting

Passing variable as a file-Scripting Help

Hi Guys, i have a file where data is in the below format:: data1 data2 data3 data4 data4 data6 my script written as:: #!/bin/ksh cd $1 at now <<END sh $2 END Here i want to pass the values stored in the above file one by one till the end of line. Here if i am doing it as:: (2 Replies)
Discussion started by: Atp3530
2 Replies

6. Programming

PASSING PART OF FILE CONTENT TO VARIABLE

All, I have a log file containing lots of data now i want to extract all text between block below(names) without the title or end pattern but only names, ++++START++++ SCOTT TIGER HENRY PAUL JARED OTIENO OMOLLO JA NIGERIA ++++END++++ the names i want to return and store in a variable in... (1 Reply)
Discussion started by: Scott2000
1 Replies

7. Shell Programming and Scripting

passing file extension using external variable

Hi, How can I modify the FILETYPE command ? I want to provide the file extension, like txt, root .? Thanks, #!/bin/bash FROM=$1 TO=$2 FILETYPE=$3 ... (4 Replies)
Discussion started by: nrjrasaxena
4 Replies

8. Shell Programming and Scripting

Passing a variable to #BSUB -n in a LSF file

Hi There! I'm writing this LSF script to make it easier to send jobs to a cluster when varying certain parameters. At one point I'd like to do something like: set NPROC = 10 and later on call BSUB using something like: #BSUB -n $NPROC unfortunately for me, this throws an error: ... (4 Replies)
Discussion started by: lrayo
4 Replies

9. Shell Programming and Scripting

replacing date with a variable in a file

Hi, I've a variable for example.. ACTIVATION_DATE=2010-11-11 (the date above is a result of a sql query and not hardcoded) now there is another file (test_2.parm) where there are many variables predefined.. REG_CODE=111 ACT_DATE=2010-10-10 CAN_DATE=8888-31-12 Now I want to search for... (1 Reply)
Discussion started by: RRVARMA
1 Replies

10. Shell Programming and Scripting

Passing output to variable instead of file

Hi, In normal shell scripting, how do you pass the output of a command to a variable, instead of a file and be able to use it later? The code is: #!/bin/bash who | cut -d" " -f1 > onlineusers Instead of passing the output of the above command to the file called 'onlineusers'... (1 Reply)
Discussion started by: Furqan_79
1 Replies
Login or Register to Ask a Question