Visit Our UNIX and Linux User Community

Passing Parameter in SED command

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Passing Parameter in SED command
# 1  
Old 06-06-2008
Passing Parameter in SED command


I am trying to replace a URL by another URL in the SED command e.g.

cat dir/filename1 | sed -e 's/"http:\/\/[^ ]*dtd"/"http:\/\/\/xyz.dtd"/' > dir/newfile.xml

But I need to pass a parameter to the SED command which should have the new url string i.e. http:\/\/\/xyz.dtd


I tried

cat dir/filename1 | sed -e 's/"http:\/\/[^ ]*dtd"/"$NEW_URL"/' > dir/newfile.xml

but instead of passing the new url, the old url was replaced by string '$NEW_URL' i.e. the parameter did not get replaced by its value.

Please help me in finding how can this be achieved.

# 2  
Old 06-07-2008
You need to use double quotes. By the way, you can also avoid cat command and avoid escaping all slashes, providing a sed "delimiter" other than "/" (in my example I've used "!"):


sed "s!http://[^ ]*dtd!${NEW_URL}!" dir/filename1 > dir/newfile.xml

# 3  
Old 06-09-2008
Thanks a lot works perfectly fine

Previous Thread | Next Thread
Test Your Knowledge in Computers #598
Difficulty: Medium
C does not support a traditional foreach loop.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Passing shell script parameter value to awk command in side the script

I have a shell script (.sh) and I want to pass a parameter value to the awk command but I am getting exception, please assist. diff=$1$2.diff id=$2 new=new_$diff echo "My id is $1" echo "I want to sync for user account $id" ##awk command I am using is as below cat $diff |... (1 Reply)
Discussion started by: Sarita Behera
1 Replies

2. Shell Programming and Scripting

Passing command as a function parameter

Hi All, Just trying to implement the below shell script using AIX ksh shell. myfunc { eval "$*" } CMD='ls -la /etc/hosts | awk '{print $9"|"$5}'' myfunc $CMD Keeping getting "|}: not found" errors, any pointers would greatly be appreciated. Kind Regards Ed Please... (2 Replies)
Discussion started by: eo29
2 Replies

3. Shell Programming and Scripting

Passing parameter to awk command

Hi, I have a situation where I need to create a SQL statement using Unix script for each value in first field (ID). The file looks like this. Id,TARGET_FIELD_NAME,SOURCE_FIELD_NAME 1,Test_Rate,Field1 1,Test_Factor,Field2 1,Test_Size,Field3 2,Test_Rate,Field4 2,Test_Factor,Field5... (3 Replies)
Discussion started by: kiranredz
3 Replies

4. Shell Programming and Scripting

Passing parameter to script, and split the parameter

i am passing input parameter 'one_two' to the script , the script output should display the result as below one_1two one_2two one_3two if then echo " Usage : <$0> <DATABASE> " exit 0 else for DB in 1 2 3 do DBname=`$DATABASE | awk -F "_" '{print $1_${DB}_$2}` done fi (5 Replies)
Discussion started by: only4satish
5 Replies

5. UNIX for Dummies Questions & Answers

Passing a Unix parameter to SQLPlus login command

hi All, i m trying to pass a user choice paramter from unix to sqlplus connect command here i want the user to enter the username and password he wants to connect in sql plus through read in unix and then automatically connect to that instance. sqlplus -s $1/$2 where $ 1 and $2 will b... (2 Replies)
Discussion started by: Jcpratap
2 Replies

6. Shell Programming and Scripting

Passing parameter in sed or awk commands to print for the specific line in a file

Hi, I am trying to print a specific line in a file through sed or awk. The line number will be passed as a parameter from the previous step. My code looks as below. TEMP3=`sed -n '$TEMP2p' $FILEPATH/Log.txt` $TEMP2, I am getting from the previous step which is a numerical value(eg:3). ... (2 Replies)
Discussion started by: satyasrin82
2 Replies

7. UNIX and Linux Applications

Passing date parameter on Kshell command line

I need to execute a .ksh from command line. The ksh calls a control file and has 3 parameters. First parameter is a csv file, second the target table in oracle and third parameter is a date parameter. I am attempting the below from the ksh command line {code} => testfile.ksh filname.csv... (1 Reply)
Discussion started by: kobe24
1 Replies

8. Shell Programming and Scripting

Passing in regular expression as a parameter to sed

Hi All, Im using Bash. I have a pipe delimited config file which contains 3 columns, 1st column = location of a file to be chnaged 2 column = expression to find within file 3rd column = string to replace. A script will loop through the contetnts of this file and apply the changes using... (2 Replies)
Discussion started by: satnamx
2 Replies

9. Shell Programming and Scripting

AT command parameter passing to php file

I have a bash script which utilizes a random function and then runs a file at now plus a random time. The problem is, that the php file requires a parameter after it eg: phpfile.php?code=123245b3 When i put in the file including the full path, with the at command, it will run, but not with... (1 Reply)
Discussion started by: thruxmore
1 Replies

10. Shell Programming and Scripting

awk/sed Command : Parse parameter file / send the lines to the ksh export command

Sorry for the duplicate thread this one is similar to the one in Since there were no responses on the parent thread since it got resolved partially i thought to open the new... (4 Replies)
Discussion started by: rajan_san
4 Replies

Featured Tech Videos