Adding prefix to the values in the script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Adding prefix to the values in the script
# 1  
Old 08-10-2010
Adding prefix to the values in the script

Hi,

test.txt contains below values
Code:
1
2
3
4
5

Desired output:
Code:
'TT.1',
'TT.2',
'TT.3',
'TT.4',
'TT.5'

Last value should not contain the comma after the value. Below is the script which i have tried. I'm using Linux.

Code:
#!/bin/bash
for i in $test.txt
do
x = 'TT.$i'
echo $x
done

Please help.

Many thanks in advance.

Last edited by Scott; 08-10-2010 at 08:15 AM.. Reason: Please use code tags
# 2  
Old 08-10-2010
Code:
$ sed "s/.*/'TT.&',/;$ s/,//" test.txt
'TT.1',
'TT.2',
'TT.3',
'TT.4',
'TT.5'

# 3  
Old 08-10-2010
To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags [code] and [/code] by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums
# 4  
Old 08-10-2010
Thanks a lot scottn.
# 5  
Old 08-10-2010
Code:
awk -v a="'" '{print a "TT." $0 a ","}' urfile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract Uniq prefix from a start and end prefix

Dear All, assume i have a file with content: <Start>6000</Start> <Stop>7599</Stop> the output is: 6000 7000 7100 7200 7300 7400 7599 how should we use any awk, sed, perl can do this task, means to extract the uniq prefixes from the start and stop prefix. Thanks Jimmy (3 Replies)
Discussion started by: jimmy_y
3 Replies

2. Shell Programming and Scripting

Adding of two column values

Hi cat /tmp/xx.txt 1 4 1 5 1 6 2 1 2 1 2 1 i want to add the values of 2nd column resepect to 1st column values..for 1 in 1st column i need sum of all the values in 2nd column ..pls tell me hw to do it?? (8 Replies)
Discussion started by: Aditya.Gurgaon
8 Replies

3. UNIX for Dummies Questions & Answers

Adding column with values

Dear all, I need your help for my question please I have without header (space separated) and need to add two colomns at the beginning with values my file look like : rs1 a t 0.6 rs2 a c 0.3 rs3 t g 0.8 I need to a new file like: 1 100 rs1 a t 0.6 1 100 rs2 a c 0.3 1 100 rs3 t g... (3 Replies)
Discussion started by: biopsy
3 Replies

4. Shell Programming and Scripting

AWK adding prefix/suffix to list of strings

75 103 131 133 138 183 197 221 232 234 248 256 286 342 368 389 463 499 524 538 (5 Replies)
Discussion started by: chrisjorg
5 Replies

5. Shell Programming and Scripting

Adding successive values in awk

Hi, I have a large log file in the following format. Epoch-Time Bytes 899726401 20 899726401 30 899726402 40 899726402 10 899726402 50 899726403 50 899726403 ... (8 Replies)
Discussion started by: sajal.bhatia
8 Replies

6. Linux

Adding a prefix to a column using awk/sed commands

Hello, I am a newbie to linux and struggling to find a better way to append a column in a text file. Here is the file i want to modify: It has 8 columns (and thousands of rows). I want to append the first column by adding "chr" infront of the numbers. Some rows have a string in the first... (4 Replies)
Discussion started by: bjorngill
4 Replies

7. Shell Programming and Scripting

dynamically adding values in c-shell

I am needing to create a variable(changing) and assign it a value(changing) ... I am using C-Shell.. Example: foreach account in ($Accountlist) set account_connect = "$account/$account_pass" end I want to make set account_connect to store various values ? $account_connect did not... (3 Replies)
Discussion started by: shafi2all
3 Replies

8. Shell Programming and Scripting

Adding values concatenating values

I have the following script in a shell # The start of a filename file=$(ls -tr $EMT*.dat | tail -1) # Select the latest file echo $file file_seq=$( < /u02/sct/banner/bandev2/xxxxxx/misc/EFTSQL.dat) echo $file_seq file2 = '$file_seq + 1' echo $file2 It is reading a file EFTSQL.dat... (3 Replies)
Discussion started by: rechever
3 Replies

9. Shell Programming and Scripting

Adding the values of two file

I have two files as Count1 and Count2. The count contains only one values as 10 and count2 contains only one values as 20. Now I want third file Count3 as count1+Count2. That is it should contain sum of two file(10+20=30) (3 Replies)
Discussion started by: Shell_Learner
3 Replies

10. Shell Programming and Scripting

adding values with a loop

Hi there, I am checking disk spaced used on a box # df -k | grep dsk | awk {'print $3'} 2055463 20165785 18310202 32274406 I want to somehow add them up but am no quite sure how to do this in a loop. ...i.e for n in 'df -k | grep dsk | awk {'print $3}' do <some adding... (1 Reply)
Discussion started by: hcclnoodles
1 Replies
Login or Register to Ask a Question