How to Append data to the content at the beginning of a variable?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to Append data to the content at the beginning of a variable?
# 1  
Old 08-18-2014
How to Append data to the content at the beginning of a variable?

Hi Guys,

IF i have to append data to a variable, i simply use the following. What can i do to append data to the beginning?
Code:
 
  VAR+="data"

# 2  
Old 08-18-2014
try
Code:
var="Makarand"
var=$var"Dodmise"
$ echo $var
MakarandDodmise

# 3  
Old 08-18-2014
Hello,

This should add text to beginning of the variable.

Code:
VAR="data" $VAR

Cheers!
Ranga
# 4  
Old 08-18-2014
Quote:
Originally Posted by rangarasan
...
Code:
VAR="data" $VAR

...
That will not work. Remove the space, and, to be sure, double-quote $VAR:
Code:
VAR="data""$VAR"

# 5  
Old 08-18-2014
Just to add a comment to these solutions, as variables get expanded inside double quotes, I would have thought only one pair of double quotes is required to enclose both the variable itself as well as the additional data:

Code:
VAR="data${VAR}"

# 6  
Old 08-18-2014
Quote:
Originally Posted by RudiC
That will not work. Remove the space, and, to be sure, double-quote $VAR:
Code:
VAR="data""$VAR"

My Bad, Typo..
# 7  
Old 08-18-2014
try

Code:
akshay@nio:~/tmp$ variable="abc"
akshay@nio:~/tmp$ printf -v variable "%s%s" def $variable
akshay@nio:~/tmp$ echo $variable
defabc

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to append in the beginning not at the end?

Hi, I now that >> will append text to the end of the text that is already inside the file. How to append the new text infront of the text that is already in the file. Thanks for any input. Regards, Chandu (3 Replies)
Discussion started by: chandrakanth
3 Replies

2. Shell Programming and Scripting

How to remove exisiting file content from a file and have to append new file content?

hi all, i had the below script x=`cat input.txt |wc -1` awk 'NR>1 && NR<'$x' ' input.txt > output.txt by using above script i am able to remove the head and tail part from the input file and able to append the output to the output.txt but if i run it for second time the output is... (2 Replies)
Discussion started by: hemanthsaikumar
2 Replies

3. Shell Programming and Scripting

Append Multiple files with file name in the beginning of line

Hi, I have multiple files having many lines like as bvelow: file Name a.txt abc def def xyz 123 5678 file Name b.txt abc def def xyz 123 5678 I would like to append files in the below format to a new file: file Name c.txt (7 Replies)
Discussion started by: rramkrishnas
7 Replies

4. Shell Programming and Scripting

Append file name to the beginning of each line

I want to append file names at the beginning of a line for each row file content abc.txt.gz 123|654|987 bcd.txt.gz 876|trf|kjh I want a single output file with below format abc.txt.gz|123|654|987 bcd.txt.gz|876|trf|kjh This one is working but only with unzip files,need to have... (3 Replies)
Discussion started by: rakesh5300
3 Replies

5. Shell Programming and Scripting

Append variable texts to the beginning of each line in all files in a directory

I am writing a code to append some numbers in the beginning of each line in all the files present in a directory. The number of files are really huge. The files are numbered as 1.sco, 2.sco, 4.sco (Note: 3.sco is missing). The files currently look like this: 1.sco 2 3 5 6 6 7My task is to... (4 Replies)
Discussion started by: shoaibjameel123
4 Replies

6. UNIX for Dummies Questions & Answers

Count Number Of lines in text files and append values to beginning of file

Hello, I have 50 text files in a directory called "AllFiles" I want to make a program that will go inside of the "AllFiles" Directory and count the number of lines in each individual text file. Then, the program will calculate how many more lines there are over 400 in each text file and... (7 Replies)
Discussion started by: motoxeryz125
7 Replies

7. Programming

Append data to smallint data in informix4gl?

Hi, I have an smallint variable, say "a", i would like to prefix it with "0" in certain conditions. Is it possible to achieve that with this datatype? For instance, a=9 --> a=09 Many thanks (1 Reply)
Discussion started by: dvah
1 Replies

8. Shell Programming and Scripting

Extract specific data content from a long list of data

My input: Data name: ABC001 Data length: 1000 Detail info Data Direction Start_time End_time Length 1 forward 10 100 90 1 forward 15 200 185 2 reverse 50 500 450 Data name: XFG110 Data length: 100 Detail info Data Direction Start_time End_time Length 1 forward 50 100 50 ... (11 Replies)
Discussion started by: patrick87
11 Replies

9. UNIX for Dummies Questions & Answers

Append to beginning of a file

Hi, I have a file x which is being upated continuously. I want to add file y in the file x but at the beginning of file x. file x file y After commands file x eeee aaaa aaaa gggg bbbb bbbb hhhh... (2 Replies)
Discussion started by: baanprog
2 Replies

10. Shell Programming and Scripting

Append (cat) to beginning of file ?

Hi, Fairly new to unix scripting, hoping to get some help. using AIX v5 Basically I have 3 files 1). Header record 2). many detail record 3). Trailer record My desired result is 1 file which contains Heaeder, Detail, Trailer Currenty I am using a series of: ... (8 Replies)
Discussion started by: CBZ
8 Replies
Login or Register to Ask a Question