Add text in front of variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Add text in front of variable
# 1  
Old 03-23-2015
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 Smilie.
# 2  
Old 03-23-2015
What is ${variant} ? It may need quoting if it contains spaces.

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

Please show your input and the output, and the output you actually wanted.
# 3  
Old 03-23-2015
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:

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

Thank you Smilie.

Last edited by rbatte1; 03-23-2015 at 02:19 PM.. Reason: Deleted erroneous ICODE tag and then added a pair for the sample input string
# 4  
Old 03-23-2015
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.
# 5  
Old 03-23-2015
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:-
Code:
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
This User Gave Thanks to rbatte1 For This Post:
# 6  
Old 03-23-2015
I chage the directory and run the printf command below to add the ${variant} to the out.txt. Thank you Smilie.

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

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

# 7  
Old 03-23-2015
c:\ ?

Are you not in a Bourne shell?

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

Code:
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.
This User Gave Thanks to Corona688 For This Post:
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 add space in front of cat values?

Hi, Hope you are all doing fine. The problem today i faced during my coding was i wanted to add a space equals to a tab character in front of all the lines which i am cat using tee command. Main file contents mainfile ... (4 Replies)
Discussion started by: mad man
4 Replies

2. Shell Programming and Scripting

awk to skip lines find text and add text based on number

I am trying to use awk skip each line with a ## or # and check each line after for STB= and if that value in greater than or = to 0.8, then at the end of line the text "STRAND BIAS" is written in else "GOOD". So in the file of 4 entries attached. awk tried: awk NR > "##"' "#" -F"STB="... (6 Replies)
Discussion started by: cmccabe
6 Replies

3. Linux

How to add \ in front of $ in a script with vi?

Please help to provide command in vi to add \ in front of $ so it does not interpret next character. rm interfaces/DART/WEB-INF/classes/DART/util/TotalDisconnectUtil$1.class rm interfaces/DART/WEB-INF/classes/DART/util/TotalDisconnectUtil$2.class rm... (3 Replies)
Discussion started by: ywu081006
3 Replies

4. Shell Programming and Scripting

[Solved] How to increment and add variable length numbers to a variable in a loop?

Hi All, I have a file which has hundred of records with fixed number of fields. In each record there is set of 8 characters which represent the duration of that activity. I want to sum up the duration present in all the records for a report. The problem is the duration changes per record so I... (5 Replies)
Discussion started by: danish0909
5 Replies

5. Shell Programming and Scripting

how to add single digit in front of the word and line in the file.

Hi , how to add the single digit to front of the word and front of the lines in the one file with compare pattern file and get digit. like example pattern file pattern.txt pattern num bala 2 raja 3 muthu 4 File Name: chennai.dat muthu is good boy raja is bad boy selvam in super... (6 Replies)
Discussion started by: krbala1985
6 Replies

6. Shell Programming and Scripting

insert predefine text in front and on a loop

Hi Experts, I wish to insert predefined text in front of every line and this needs to be in a loop because it is always expanding. Before : 11111111 22222222 33333333 44444444 55555555 77777777 88888888 00000000 To be Inserted : a= b= (2 Replies)
Discussion started by: masayangbata
2 Replies

7. Shell Programming and Scripting

How join line and add | in front

Hello, Did any one know how to use perl join line and add | in front Input--> timestamp=2009-11-10-04.55.20.829347; a; b; c; ddaa; timestamp=2009-11-10-04.55.20.829347; aa; bb; cc; Output--> ... (2 Replies)
Discussion started by: happyday
2 Replies

8. Shell Programming and Scripting

SED: Extracting text between first occurance of foo in front of bar

Suppose I have a text file that contains the tags <foo> and <bar>. The text file can have unlimted occurances of <foo> and <bar> and looks somthing like this: <foo> Some Text <foo> Some Text <bar> Some Text <foo> Some (1 Reply)
Discussion started by: ArterialTool
1 Replies

9. Shell Programming and Scripting

Want to add a word in front a of each line of a file

Hi, Can anybody help me how to add a word in front of a line in a file.Actually it is bit tricky to add a word. i will give a sample for this: Input : 1110001 ABC DEF 1110001 EFG HIJ 1110001 KLM NOP 1110002 QRS RST 1110002 UVW XYZ Output: %HD% 1110001 ABC DEF %DT% 1110001 EFG HIJ... (4 Replies)
Discussion started by: apjneeraj
4 Replies

10. Shell Programming and Scripting

bash - add backslash in front of variables w/ spaces

Hello, Im writing a script that works by recursively going into directories with find. But I have some directories that have spaces in them.. so I need to parse the variables to add a backslash before the spaces. Im not exactly sure how how to do this in bash, and honestly I dont think I know... (3 Replies)
Discussion started by: trey85stang
3 Replies
Login or Register to Ask a Question