Adding a new column to an existing one


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Adding a new column to an existing one
# 1  
Old 08-30-2012
Adding a new column to an existing one

I have a data file that looks like this:
Code:
0.01 1 3822 4.97379915032e-14 4.96982253992e-09 0
0.01 3822 1 4.97379915032e-14 4.96982253992e-09 0
0.01 2 502 0.00993165137406 993.165137406 0
0.01 502 2 0.00993165137406 993.165137406 0
0.01 4 33 0.00189645523539 189.645523539 0
0.01 33 4 0.00189645523539 189.645523539 0
0.01 4 548 0.00357382134942 357.382134942 0
0.01 548 4 0.00357382134942 357.382134942 0
0.01 4 1225 0.00088154447822 88.154447822 0
0.01 1225 4 0.00088154447822 88.154447822 0
0.01 4 868 0.00295939726649 295.939726649 0
0.01 868 4 0.00295939726649 295.939726649 0

I would like to insert the second column of this file:
Code:
0.0065162728198 0.0
0.00644329906428 3.2501728e-05
0.00639487858574 0.00013040088
0.00708128785164 0.00029330348
0.00901786983409 0.00052140653
0.0121446142468 0.00081431604
0.0161551067947 0.0011719336
0.0207759449093 0.0015940621
0.0258367282968 0.0020803076
0.0312844712596 0.0026306703
0.0360590712239 0.0032444606
0.0423387742368 0.0039214813

to the last column of the former. Could somebody show me how to do this with awk or grep?
# 2  
Old 08-30-2012
Try this..

Code:
paste file1 file2 | awk '{ $(NF-1)=""}1'

# 3  
Old 08-30-2012
Code:
cut -f2 -d' ' file2|paste -d' ' file1 -

# 4  
Old 08-30-2012
perfect! Thanks! You guys are great!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Matching column then append to existing File as new column

Good evening I have the below requirements, as I am not an experts in Linux/Unix and am looking for your ideas how I can do this. I have file called file1 and file2. I need to get the second column which is text1_random_alphabets and find that in file 2, if it's exists then print the 3rd... (4 Replies)
Discussion started by: mychbears
4 Replies

2. Shell Programming and Scripting

Adding a new column in a file with other existing columns

Hi All , Kindly help me with this soln awk '{printf "%s %7s \n", $1,$c}' infile where value of variable c I am externally giving input But executing the above command shows all the columns of infile where as I want only 1st column of infile and 2nd column should print value c (8 Replies)
Discussion started by: Pratik4891
8 Replies

3. Shell Programming and Scripting

Adding New Selections to the existing Script

Hi.... i have two scripts called: "type" & "selecttype". In "type" i have only the name of the products ex.: product1 & product2. Now, i have to ADD product3 which includes sub categories: productA, productB, productC, productD, productE, productF. so my New type script (menu) looks as... (1 Reply)
Discussion started by: Netrock
1 Replies

4. Web Development

Adding a Web Calendar to an existing Groupware

Hi All, I have an existing groupware consisting of postfix,dovecot,openldap and webmail(RoundCube). But It lacks a shared calendar. Can someone advise how can I implement a calendar in my groupware ? Thanks. (1 Reply)
Discussion started by: coolatt
1 Replies

5. Shell Programming and Scripting

Adding new fields to an existing layout

Hi Everybody, I have an layout file like below f1 1 char 10, f2 11 char 2, f3 13 char 1, lineend 14 char 1 Their I need to add a new field which would be like f5 char 3, f6 char 2 The o/p should be f1 1 char 10, f2 11 char 2, f3 13 char 1, f5 14 char 3, f6 17 char 2 (3 Replies)
Discussion started by: mr_manii
3 Replies

6. Shell Programming and Scripting

Adding file to an existing tar

Hi Friends, I want to know the command to add a new file in a existing tar file. For Ex: I have a tar file file1.tar with the contents one.txt two.txt three.txt Now I need to add file four.txt to this existing tar file, how can I do it? Thanks in advance (4 Replies)
Discussion started by: mr_manii
4 Replies

7. Linux

Adding space to existing mount

I am on Red Hat Linux 4.7. I am getting this error message: Preparing... ########################################### You have insufficient diskspace in the destination directory (/usr/lib) to install xxxxxxxxxxxxx. The installation requires at least 1.5 GB free on this... (2 Replies)
Discussion started by: jxh461
2 Replies

8. UNIX for Dummies Questions & Answers

Adding header to an existing file

Dear All, I need to add a header of one line to an already existing file. I know that it can be achieved by the following: echo "Header" > newfile cat file1 >> newfile But my problem is that file is huge and there is no space for creating a new file every time. Is there a way that I can... (5 Replies)
Discussion started by: shash
5 Replies

9. Solaris

adding existing disks to a 3510 array

I would like to extend a logical drive on our 3510. I have four unallocated disks which I would like to use for this purpose. The 3510 supports a Sun Cluster but for now all I wish to see is a "new" disk when I run format. I am a little familiar with the telnet/ssh session on the 3510 but am... (2 Replies)
Discussion started by: malcqv
2 Replies

10. Solaris

SMF - Adding instances to existing manifest

I have a default, sun supplied, apache2 install on solaris10. It's running fine, everything's great. I'm looking to add another instance, fairly happy with how to do that apart from one thing - the SMF manifest. Can i just edit the XML file sun supplied for the default apache2 and add in details... (2 Replies)
Discussion started by: craigp84
2 Replies
Login or Register to Ask a Question