Adding additional column at the end


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Adding additional column at the end
# 1  
Old 12-04-2009
Power Adding additional column at the end

I have a file like below. The separator between reconds is ">" Each record consists of 2 numbers separated by a space.

I want to write an awk script that copies the second number and puts it in the third column. Smilie

Code:
>
10 0 
13 5.92346 
16 10.3106 
19 13.9672 
22 16.9838 
25 19.4407 
28 21.4705 
31 23.1547 
34 24.6813 
37 26.0695 
>
40 27.3611 
43 28.631 
46 29.8366 
49 30.9858 
52 32.0934 
55 33.1458 
58 34.1637 
61 35.1297 
64 36.0253 
67 36.9248 
70 37.8001 
>


Last edited by zaxxon; 12-04-2009 at 08:55 AM.. Reason: code tags
# 2  
Old 12-04-2009
Can you post an example of your desired output based on the file above?
# 3  
Old 12-04-2009
Done it Smilie Thanks
# 4  
Old 12-04-2009
Not sure if this is what you need; if not, post an example of the expected output please:
Code:
$> awk 'NF > 1 {print $0,$2; next} {print}' infile
>
10 0  0
13 5.92346  5.92346
16 10.3106  10.3106
19 13.9672  13.9672
22 16.9838  16.9838
25 19.4407  19.4407
28 21.4705  21.4705
31 23.1547  23.1547
34 24.6813  24.6813
37 26.0695  26.0695
>
40 27.3611  27.3611
43 28.631  28.631
46 29.8366  29.8366
49 30.9858  30.9858
52 32.0934  32.0934
55 33.1458  33.1458
58 34.1637  34.1637
61 35.1297  35.1297
64 36.0253  36.0253
67 36.9248  36.9248
70 37.8001  37.8001
>

You wrote:
Quote:
The separator between reconds is ">"
I guess you mean paragraph instead of "reconds".

Last edited by zaxxon; 12-04-2009 at 09:38 AM.. Reason: typo
# 5  
Old 12-04-2009
So now I need to solve this one:

Now I have a file like below. I want to take each paragraph between the ">" and

Find the line for which the second and third column is 0. Take the first value.

For example I find 10 0 0 from first paragraph and get the 10.

Then take each line and get the first value and subtract it from 10.

ie

10-10
13-10
16-10
19-10
22-10

If the result is greater than 40 I need to remove the row. Trying to do it in awk.

Do the same for the second section

Find 50 0 0, then take the 50

Subtract first column value from each line in section between ">" from 50. If result greater than 40, remove the row from the file.

etc for all the sections between the ">".

Code:
>
10 0 0
13 5.92346 5.92346
16 10.3106 10.3106
19 13.9672 13.9672
22 16.9838 16.9838
25 19.4407 19.4407
28 21.4705 21.4705
31 23.1547 23.1547
34 24.6813 24.6813
37 26.0695 26.0695
>
40 27.3611 27.3611
43 28.631 28.631
46 29.8366 29.8366
49 30.9858 30.9858
50 0 0
52 32.0934 32.0934
55 33.1458 33.1458
58 34.1637 34.1637
61 35.1297 35.1297
64 36.0253 36.0253
67 36.9248 36.9248
70 37.8001 37.8001
>


Last edited by kristinu; 12-04-2009 at 11:03 AM..
# 6  
Old 12-07-2009
Code:
nawk 'NF==2{$3=$2}{print}'

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Format a date on additional column awk

Hi, My objective is to achieve from HB.txt 05/20/1997,1130,5.93,5.96,5.93,5.96,49200 05/20/1997,1131,5.96,5.96,5.9,5.93,252400 05/14/1997,1132,5.93,5.99,5.93,5.99,89600 05/15/1997,1133,5.93,5.93,5.71,5.74,203200 into adding a day column by using the first column - date. ... (9 Replies)
Discussion started by: benchin_
9 Replies

2. Red Hat

Adding Additional Capacity with megacli

I'm trying to add 6 more hard drives to my RAID array, none of the drives are foreign, they won't be replacing any drives either. I just need to add them to the RAID array. I can't seem to get them added, what am I missing? ---------- Post updated 08-03-12 at 12:28 PM ---------- Previous... (0 Replies)
Discussion started by: eccentricson
0 Replies

3. Shell Programming and Scripting

Adding an additional blank field to a file

Hi, I have the following file, I'd like to add an additional blank field to this file This is a tab delimited file, I have tried the same thing on excel, but looking for a unix solution. Here is my input: Country Postal Admin4 StreetBaseName StreetType HUN 2243 Kóka Dózsa György ... (3 Replies)
Discussion started by: ramky79
3 Replies

4. Shell Programming and Scripting

add a additional column in csv file

Thanks for allwoing me to discuss in this forum GIVEN BELOW A simple shell script which will ask for the user to input a PC name and it will produce the output in CSV with the PC name #! /bin/bash read -p "enter the PC name :" pc #checking for netstat report netstat -pant |sed '1,2d'... (1 Reply)
Discussion started by: ayyappancheta
1 Replies

5. AIX

Any Additional Steps After Adding New RAM To Sever?

Hi All, We have a server at a client site running AIX 5.3, which we just up the RAM to 32GB, from initially 16GB (if I'm not mistaken). This server is our Application server running J2EE applications on top of Oracle Internet Application Server. Recently we encountered one of the batch jobs... (12 Replies)
Discussion started by: a_sim
12 Replies

6. Shell Programming and Scripting

Adding additional characters while preserving original text

Hi Forum. I'm struggling on this relatively easy request to add additional 4 0's to an existing text in a file (whenever I see the pattern -# where # represents any number) using sed command while preserving the rest of the text in the files. Original Text: $DBConnection_EDW=SAS2EDW... (5 Replies)
Discussion started by: pchang
5 Replies

7. UNIX for Advanced & Expert Users

adding additional drive to sco the is xenix

I am taking an old xenix drive and installing it in a recent SCO Build Server. I have gone through the process of running mkdev hd twice since the drive is a SCSI then proceed to run mkdev fs and when I attempt to add one of the shown partitions I get the following: fsck: cannot determine... (1 Reply)
Discussion started by: justenglabs
1 Replies

8. UNIX for Dummies Questions & Answers

Adding an additional harddrive in solaris 9

Hello, I have a system which a new harddrive was installed for additional space. I now need to mount the drive and transfer data from /home to the new drive with a mount point named /home. How do I go about doing this? Thanks in advance. (5 Replies)
Discussion started by: GLJ@USC
5 Replies

9. UNIX for Dummies Questions & Answers

adding a column at the end of the record

hello., i have a .txt file. inside the .txt file i have., /home/ss/cca.costco.transaction_date /home/sk/cca.costco.transaction_date /home/st/cca.costco.transaction_date /home/sv/cca.costco.transaction_date cca.costco.transaction_date is the file name. inside the file there are some... (2 Replies)
Discussion started by: pavan_test
2 Replies
Login or Register to Ask a Question