changing and appending numbers


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting changing and appending numbers
# 1  
Old 08-17-2011
changing and appending numbers

I have a file that looks like below but i need to add the second part to the first meaning in the part where it goes from 14 to 1 in the first column to go to 14 to 15 and the same with the right side going from 2 to 1 to go to 2 to 3. THanks


Code:
   1  176.587  0.015      C 1
   2   57.351  0.000     CA 1
   3   34.282  0.000     CB 1
   4   33.675  0.075     CG 1
   5    4.346  0.003     HA 1
   6    1.782  0.000     HB 1
   7    2.211  0.000     HG 1
   8  177.179  0.012      C 2
   9   57.400  0.000     CA 2
  10   35.680  0.000     CB 2
  11   31.136  0.000     CD 2
  12   43.939  0.000     CE 2
  13   26.463  0.000     CG 2
  14    8.549  0.018      H 2
   1  176.587  0.015      C 1
   2   57.351  0.000     CA 1
   3   34.282  0.000     CB 1
   4   33.675  0.075     CG 1
   5    4.346  0.003     HA 1
   6    1.782  0.000     HB 1
   7    2.211  0.000     HG 1
   8  177.179  0.012      C 2
   9   57.400  0.000     CA 2
  10   35.680  0.000     CB 2
  11   31.136  0.000     CD 2
  12   43.939  0.000     CE 2
  13   26.463  0.000     CG 2
  14    8.549  0.018      H 2


Last edited by pludi; 08-17-2011 at 06:57 PM..
# 2  
Old 08-17-2011
Can you display the desired output?
# 3  
Old 08-17-2011
Here is the output i would like.


Code:
1 176.587 0.015 C 1
2 57.351 0.000 CA 1
3 34.282 0.000 CB 1
4 33.675 0.075 CG 1
5 4.346 0.003 HA 1
6 1.782 0.000 HB 1
7 2.211 0.000 HG 1
8 177.179 0.012 C 2
9 57.400 0.000 CA 2
10 35.680 0.000 CB 2
11 31.136 0.000 CD 2
12 43.939 0.000 CE 2
13 26.463 0.000 CG 2
14 8.549 0.018 H 2
15 176.587 0.015 C 3
16 57.351 0.000 CA 3
17 34.282 0.000 CB 3
18 33.675 0.075 CG 3
19 4.346 0.003 HA 3
20 1.782 0.000 HB 3
21 2.211 0.000 HG 3
22 177.179 0.012 C 3
23 57.400 0.000 CA 3
24 35.680 0.000 CB 3
25 31.136 0.000 CD 3


Last edited by pludi; 08-17-2011 at 06:58 PM..
# 4  
Old 08-17-2011
Code:
awk '{$1=NR;$NF=NR%7?int(NR/7)+1:NR/7}1' file

# 5  
Old 08-18-2011
Which part of that awk code modifies only the first column for sequential numbering?\

EDIT
I figured it out, thanks for the help!

Last edited by olifu02; 08-18-2011 at 11:15 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Decimal numbers and letters in the same collums: round numbers

Hi! I found and then adapt the code for my pipeline... awk -F"," -vOFS="," '{printf "%0.2f %0.f\n",$2,$4}' xxx > yyy I add -F"," -vOFS="," (for input and output as csv file) and I change the columns and the number of decimal... It works but I have also some problems... here my columns ... (7 Replies)
Discussion started by: echo manolis
7 Replies

2. UNIX for Dummies Questions & Answers

Appending a column of numbers in ascending order to a text file

I have a text file where I want to append a column of numbers in ascending orders. Input: 57 abc 25 def 32 ghi 54 jkl Output:57 abc 57 abc 1 25 def 2 32 ghi 3 54 jkl 4 How do I go about doing that? Thanks! (11 Replies)
Discussion started by: evelibertine
11 Replies

3. UNIX for Dummies Questions & Answers

Print numbers and associated text belonging to an interval of numbers

##### (0 Replies)
Discussion started by: lucasvs
0 Replies

4. Shell Programming and Scripting

the smallest number from 90% of highest numbers from all numbers in file

Hello All, I am having problem to find what is the smallest number from 90% of highest numbers from all numbers in file. I am having file with thousands of lines and hundreds of columns. I am familiar mainly with bash but I am open to whatever suggestion witch will lead to the solutions. If I... (11 Replies)
Discussion started by: Apfik
11 Replies

5. UNIX for Dummies Questions & Answers

appending running numbers on a variable

hi guys, would appreciate some help here. I need to append running numbers using sed onto a variable that contain a list of IP addresses. I'm basically stuck on the running number part. e.g. 1. 10.0.0.1 2. 10.0.0.2 3. 10.0.0.3 (10 Replies)
Discussion started by: jazzaddict
10 Replies

6. Shell Programming and Scripting

appending zeros to numbers using awk

hi i want to append zeros to a given number ( varying digits). the total length of the output should be 10 digits. For example: 1)input is var=347 output should be NewVar=0000000347 2) input is var=123456 output should be NewVar=0000123456 i am able to acheive this using typeset... (1 Reply)
Discussion started by: somi2yoga
1 Replies

7. Shell Programming and Scripting

read numbers from file and output which numbers belongs to which range

Howdy experts, We have some ranges of number which belongs to particual group as below. GroupNo StartRange EndRange Group0125 935300 935399 Group2006 935400 935476 937430 937459 Group0324 935477 935549 ... (6 Replies)
Discussion started by: thepurple
6 Replies

8. UNIX for Dummies Questions & Answers

seperating records with numbers from a set of numbers

I have two files one (numbers file)contains the numbers(approximately 30000) and the other file(record file) contains the records(approximately 40000)which may or may not contain the numbers from that file. I want to seperate the records which has the field 1=(any of the number from numbers... (15 Replies)
Discussion started by: Shiv@jad
15 Replies

9. Shell Programming and Scripting

Changing values with increasing numbers!

Hi all, i have a command named "vmchange" and i must use it for thousands of data which must be changed. For example, vmchange -m N0001 vmchange -m N0002 vmchange -m N0003 ... ... vmchange -m N0100 How can i do that in awk or bash script? Any help would be greatly appreciated.. ... (5 Replies)
Discussion started by: oduth
5 Replies

10. Shell Programming and Scripting

Changing userID and Changing group and GID

Hello, I want to write a ksh script about changing UID and changing group with GID. There are multiple servers i want to perform that job. linux1 linux2 linux3 linux4 linux5 ...... . . . . . 1.) How can i enter "password" in script rather asking me? I was trying this... ssh... (2 Replies)
Discussion started by: deal732
2 Replies
Login or Register to Ask a Question