Parameter substitution is not working with sed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Parameter substitution is not working with sed
# 1  
Old 03-06-2017
Parameter substitution is not working with sed

I am trying add a prefix variable(string) to command output.
sed parameter substitution is not working.

- I have found some issues on my end of testing,, please delete this thread for now.

Last edited by kchinnam; 03-06-2017 at 06:58 PM.. Reason: confusion
# 2  
Old 03-06-2017
You define a variable named prefix. You expand a variable named myprefix. Try:
Code:
prefix='myprefix'; echo "chr, aaaaa|bbbbbb" | sed "s/^/$prefix,/"

which produces the output:
Code:
myprefix,chr, aaaaa|bbbbbb

This User Gave Thanks to Don Cragun For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Simple Variable substitution in ksh not working

Hi Gurus, Not able to catch what's going wrong here. I just want to get output as "tree". server:/mk/app/nexapp $ echo $SHELL /usr/bin/ksh server:/mk/app/nexapp $ export db_name1="tree" server:/mk/app/nexapp $ export i=1 1st try: server:/mk/app/nexapp $ echo $(db_name$i) ksh: db_name1: ... (3 Replies)
Discussion started by: mukesh.lalwani
3 Replies

2. Shell Programming and Scripting

Does awk have parameter substitution?

Can I specify a default value to a variable in AWK like BASH in one statement using parameter substitution? BASH example: argument=${$1-"default if empty"} (BASH) I know I can do: argument=$1; sub ( "^$", "default if empty", argument) (AWK) Mike (13 Replies)
Discussion started by: Michael Stora
13 Replies

3. Shell Programming and Scripting

Bad substitution error while working with substring

Hi I'm using ksh. And i'm trying to get the substring like below. but giving the following error #!/bin/ksh foo=teststring bar=${foo:0:5} echo $bar And the error is ./sbstr_test.sh: bar=${foo:0:5}: bad substitution what is wrong in this script. Please correct me ... (3 Replies)
Discussion started by: smile689
3 Replies

4. Shell Programming and Scripting

Parameter substitution with##

Hi experts I want to use the parameter substitution in the bash with ## to get a=mfs1000 (not the "mfs" maybe other string and the length is not the same" I want to get 1000 any help? I don't know use which pattern I use echo ${a##*} It doesn't work Lei (5 Replies)
Discussion started by: yanglei_fage
5 Replies

5. Shell Programming and Scripting

Parameter expansion not working for all strings...

I'm trying to write a script that parses my music collection and hard link some filenames that my media player doesn't like to other names. To do this I need to extract the name and remove alla non ASCII characters from that and do a cp -l with the result. Problem is this: 22:16:58 $... (8 Replies)
Discussion started by: refuser
8 Replies

6. UNIX for Dummies Questions & Answers

Parameter substitution with alias

Hello, in my .bashrc I tried to setup some aliases. alias scp_cmd="scp -P 8888 $1 me@somehost:." is supposed to copy a local file to somehost via scp. However it seems that the command line substitution does not work here. However this works: alias lst="ls -l $1" The above scp command can... (1 Reply)
Discussion started by: strobotta
1 Replies

7. UNIX for Advanced & Expert Users

Formatting Substitution Command Not Working in vi

Unix Gurus, I have a text file I have FTP'd to UNIX so that I can use it to load into our Baan system. When vi the file, I can see that there are formatting characters at the end of each line (^M). To get rid of these, I have read that the following should work: :%s/^M$//g - with the ^M... (11 Replies)
Discussion started by: ERPKEN
11 Replies

8. Solaris

Substitution not working in ksh

Hi, Following code is working in bash but not in ksh. Can someone please send me an alternative? #!/bin/ksh fname="EOA.dmp" echo $fname logname=${fname/.dmp/.log} echo $logname I am getting below error in ksh "testcmd: logname=${fname/.dmp/.log}: 0403-011 The specified substitution... (3 Replies)
Discussion started by: arsheshadri
3 Replies

9. AIX

Substitution not working in ksh

Following code is working in bash but not in ksh. Can someone please send me an alternative? #!/bin/ksh fname="EOA.dmp" echo $fname logname=${fname/.dmp/.log} echo $logname I am getting below error in ksh "testcmd: logname=${fname/.dmp/.log}: 0403-011 The specified substitution is not... (2 Replies)
Discussion started by: arsheshadri
2 Replies

10. Shell Programming and Scripting

Var substitution in awk - not working as expected

countA=`awk '/X/''{print substr($0,38,1)}' fName | wc -l` countB=`wc -l fName | awk '{print int($1)}'` echo > temp ratio=`awk -va=$countA -vc=$countB '{printf "%.4f", a/c}' temp` After running script for above I am getting an error as : awk: 0602-533 Cannot find or open file -vc=25. The... (3 Replies)
Discussion started by: videsh77
3 Replies
Login or Register to Ask a Question