Numerical calculation by any programming language or Awk ??


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Numerical calculation by any programming language or Awk ??
# 1  
Old 07-21-2010
Numerical calculation by any programming language or Awk ??

I will try to explain directly how the input and output looks like and the way to produce output

every line in output comes from columns 2 (
78507634), 3(78534748) and 11(last but one), 12(last).

For example line1 in output comes from

col2(78507634)+col12 1st value(0) = 78507634
78507634+ col11 1st value (29) = 78507663


For example line2 in output comes from

col2(78507634)+col12 2nd value(808) = 78508442
78508442+ col11 2nd value (188) = 78508630



input

Code:
c1    78507634    78534748    G_X    0    +    78508536    78534673    0    7    29,188,179,205,175,200,230,    0,808,11625,12514,16510,17993,26884,

output
Code:
c1    78507634    78507663    1stE_G_X
c1    78508442    78508630    2ndE_G_X
c1    78519259    78519438    3rdE_G_X
c1    78520148    78520353    4thE_G_X
c1    78524144    78524319    5thE_G_X
c1    78525627    78525827    6thE_G_X
c1    78534518    78534748    7thE_G_X


Last edited by repinementer; 07-21-2010 at 08:33 PM.. Reason: wrong input
# 2  
Old 07-21-2010
Quote:
col2(78507634)+col11 1st value(0) = 78507634
78507634+ col12 1st value (29) = 78507663
col11 1st value is 29 and col12 1st value is 0 or I'm missing something?

If you want the output you posted:

Code:
awk '{
  n11 = split($11, t11, ",")
  n12 = split($12, t12, ",")
  for (i = 0; ++i < n11;) {
    s12 = $2 + t12[i]
	print $1, s12, s12 + t11[i]
    }
  }' infile

If the description is semi-correct and the output wrong:

Code:
awk '{
  n11 = split($11, t11, ",")
  n12 = split($12, t12, ",")
  for (i = 0; ++i < n11;) {
    s11 = $2 + t11[i]
	print $1, s11, s11 + s12[i]
    }
  }' infile

P.S. I didn't include the last column, because I don't now how it is generated.
# 3  
Old 07-21-2010
trying to understand...

input file, many lines
Code:
x c2 c3 x x x x x x x c11a,c11b,c11c c12a,c12b,c12c

thus that output is simplified:
Code:
c2+c12a c2+c11a

If so, then when is c3 value used?
# 4  
Old 07-21-2010
Hi All My apologies for the erroneous post

Now I modified the instructions.

@ rad: yes you are right the first mistake you identified is the error (confusion of 11th and 12 columns)

Thank you for correcting me
# 5  
Old 07-21-2010
Quote:
Originally Posted by joeyg
input file, many lines
Code:
x c2 c3 x x x x x x x c11a,c11b,c11c c12a,c12b,c12c

thus that output is simplified:
Code:
c2+c12a c2+c11a

If so, then when is c3 value used?
agree, c3 is never used.

And c11 and c12 should be same segments.

Code:
c1 c2+c12(1) c2+c12(1)+c11(1)
c1 c2+c12(2) c2+c12(2)+c11(2)
...

# 6  
Old 07-22-2010
HI

Rad first script doing the job perfectly
Code:
awk '{
  n11 = split($11, t11, ",")
  n12 = split($12, t12, ",")
  for (i = 0; ++i < n11;) {
    s12 = $2 + t12[i]
	print $1, s12, s12 + t11[i]
    }
  }' infile

How ever
Quote:
P.S. I didn't include the last column, because I don't now how it is generated.
The last column is just referring 1stline and 4th value in input (1stE_G_X)
# 7  
Old 07-22-2010
Quote:
Originally Posted by repinementer
[...]
How ever

The last column is just referring 1stline and 4th value in input (1stE_G_X)
I still don't understand: 4th field value is G_X and you want:

Code:
1stE_G_X
2ndE_G_X
...

What's the logic behind G_X <-> E_G_X?
You know, it's easy to generate progressive numbers, not 1st, 2nd etc, do you really need them like this?
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Programming

How is a new Web Development language written ?

I'm wondering how programmers develop new Web Development languages because I want to learn how everything begins from the start. Let's say I'm planning to write a new language for the Web. How do I do this? Is there anyone who knows about the way Web Development languages first appear ? I'm... (3 Replies)
Discussion started by: Anna Hussie
3 Replies

2. Programming

What Programming language should I start learning first?

I want to create a computer program that will translate from English to Spanish and vice versa. So someone could type in a word, phrase, or paragraph and translate from one language to another. What programming language would I use to write up the code and then implement this program? I want to... (8 Replies)
Discussion started by: Anna Hussie
8 Replies

3. Programming

How is a new Web Development language written ?

I'm wondering how programmers develop new Web Development languages because I want to learn how everything begins from the start. Let's say I'm planning to write a new language for the Web. How do I do this? Is there anyone who knows about the way Web Development languages first appear ? I'm asking... (1 Reply)
Discussion started by: Anna Hussie
1 Replies

4. UNIX for Dummies Questions & Answers

Is PERL a programming language?

I need a small and simple clarification... Can someone tell me whether PERL is a programming language or not. Also, can shell scripts also considered as programming language or not. Also, please tell me the exact difference between programming language and scripting. Please help.... (3 Replies)
Discussion started by: Anjan1
3 Replies

5. UNIX for Dummies Questions & Answers

Carreer:Networking Programming in Unix (C programming Language)

Hello, I am trying to learn Networking Programming in C in unix enviorment. I want to know how good it is to become a network programmer. i am crazy about Network programming but i also want to opt for the best carreer options. Anybody experienced Network Programmer, please tell me is my... (5 Replies)
Discussion started by: vibhory2j
5 Replies

6. Programming

c programming language

Can someone enligten me on what below program does? I understand getchar and putchar.. but what is this program suppose to do? I try to put printf on it, but it shows nothing.. can someone explain to me what this program is suppose to do? It is reading something and assigning to c? so, if... (8 Replies)
Discussion started by: convenientstore
8 Replies

7. UNIX for Dummies Questions & Answers

Does the programming language matters?

I see you guys encouraged people studied and used C while they were working on UNIX. Does C++ or JAVA matter? And in the past threads, Neo, PxT, and other members recommanded lots good books. I think those people who asked for the references, such as Dominic, had experiences on sys admin or... (8 Replies)
Discussion started by: HOUSCOUS
8 Replies
Login or Register to Ask a Question