Add text in front of variable

I am just trying to add specific text in front of a ${variant} but can not seem to get the syntax correct.

I have tried sed -i '$a NM_004004.5' ${variant} and printf "NM_004004.5:%s\n" ${variant} with no luck.

Thank you :).

What is ${variant} ? It may need quoting if it contains spaces.

printf "NM_004004.5:%s\n" "${variant}"

Please show your input and the output, and the output you actually wanted.

I added the printf "NM_004004.5:%s\n" ${variant}" and attached the output.

${variant} is a variable that stores the user input.

For example, if the user inputs c.79G>A,c.283G>C

then out.txt would look like:

NM_004004.5:c.79G>A
NM_004004.5:c.283G>T 

Thank you :).

I have absolutely no idea why your output file contains the text printf.

Please show exactly what you are doing to get this output, word for word, letter for letter, keystroke for keystroke.

I don't see where the T comes from in your output, but it seems that your input is actually two comma separated values. Is this true?

If so, you will need to split them up to then display the output you want.

You could try:-

v1="${variant%,*}"
v2="${variant#*,}"

printf "NM_004004.5:%s\nNM_004004.5:%2" "${v1}" "${v2}"

Without knowing the overall objective clearly it's a little difficult to guess.

Am I anywhere near the requirement?

Robin

1 Like

I chage the directory and run the printf command below to add the ${variant} to the out.txt. Thank you :).

 cd 'C:\Users\cmccabe\Desktop\annovar'

 printf "NM_004004.5:%s\n" ${variant} >> C:\Users\cmccabe\Desktop\annovar\out.txt

c:\ ?

Are you not in a Bourne shell?

If this is Cygwin in Windows or the like, you probably want to do

printf "NM_004004.5:%s\r\n" "${variant}" >> C:\Users\cmccabe\Desktop\annovar\out.txt

so it ends up as a Windows-style text file, not a UNIX one.

You also forgot to quote it again.

1 Like

Thank you :slight_smile: works great.