How to extract elements in a field using a number

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to extract elements in a field using a number
# 15  
Old 12-13-2007
Hi porter,

The formula is supposed to be ($j)/($i+$j) not the other way round.Anyway, I still cant get the calculation to float which in debug mode it gives

++ echo '(6.00000)/(5.00000' '+6.00000)'

which output value q=0 rather than float.

My code is:-
q=` echo \($j.00000\)\/\($i.00000 +$j.00000\)|bc`

Please advise. Thanks.

# 16  
Old 12-13-2007
$ i=5
$ j=6
$ k=`echo $i $j |awk '{printf("%f",($2/($1+$2)))}'`
$ echo $k

# 17  
Old 12-13-2007

echo scale=4\; $j + \( $j + $i \) | bc

# 18  
Old 12-13-2007
Hi porter,

I tried before on scaling method and i do not know how to turnaround especially in my scenario.

Thanks. I managed to use rikxik formula and it is working. The reason is because i am actually parsing the whole echo to a variable rather than echo alone.

However, on the other note, I still havent resolve the grep problem where it still return me any value which is matching the number rather than exact number (grep -n number$ filename).Still finding what character I missed out to isolate the "$" so that the number is uniquely grabbed from the file.

If you have any idea, let me know.

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Awk: count unique elements in a field and sum their occurence across the entire file

Hi, Sure it's an easy one, but it drives me insane. input ("|" separated): 1|A,B,C,A 2|A,D,D 3|A,B,B I would like to count the occurence of each capital letters in $2 across the entire file, knowing that duplicates in each record count as 1. I am trying to get this output... (5 Replies)
Discussion started by: beca123456
5 Replies

2. UNIX for Beginners Questions & Answers

How can we extract specific elements from XML?

Hi, I have a requirement to extract specific element value dynamically from XML message. Here is the sample message: <File> <List> <main> <dir>doc/store834/archive</dir> <count>5</count> </main> <main> <dir>doc/store834/extract</dir> <count>6</count> </main> <main> ... (3 Replies)
Discussion started by: renukeswar
3 Replies

3. Shell Programming and Scripting

Issue with the incorrect number of array elements

Hello , I have a file : RestartSession.txt with the below contents : Backup p203pcrw01_OS_Weekly Failed full 10/11/2015 10:00:07 PM 1444572007 10/11/2015 10:26:23 PM 1444573583 0:00 0:26 18.76 1 08 0 0 0 2 2 180668 ... (4 Replies)
Discussion started by: rahul2662
4 Replies

4. UNIX for Dummies Questions & Answers

Sort array elements from same field

Hi, input: line1|error_type_a@15 line1|error_type_c@10 line1|error_type_b@5 line2|error_type_f@3 line2|error_type_a@1 I would need to place all the second fields with common first field on the same line, BUT with sorted error position number: line1|error_type_b@5; error_type_c@10;... (5 Replies)
Discussion started by: beca123456
5 Replies

5. Shell Programming and Scripting

Extract only required elements from XML.

Hi , I have an XML like this. <Request> <SOAP-ENV:Envelope xmlns:SOAP-ENV=""> <version>v44</version><messageId>7247308192</messageId><timeToLive>72000000000</timeToLive> </Request>. I want to extract on version and messageId. As in my output... (13 Replies)
Discussion started by: chetan.c
13 Replies

6. Shell Programming and Scripting

Get number of elements in a list

Hi all I would like to know the number of elements in a list. $list=`ls xyz*` I want to get the number of files xyz* in the folder. Anybody please help!!! (5 Replies)
Discussion started by: VidyaVenugopal
5 Replies

7. Shell Programming and Scripting

Sorting on two fields time field and number field

Hi, I have a file that has data in it that says 00:01:48.233 1212 00:01:56.233 345 00:09:01.221 5678 00:12:23.321 93444 The file has more line than this but i just wanted to put in a snippet to ask how I would get the highest number with time stamp into another file. So from the above... (2 Replies)
Discussion started by: pat4519
2 Replies

8. Shell Programming and Scripting

Number of elements in Word list

Hello everyone, can anyone let me know if there is a way to get the count of elements in a word list that I use for a for loop in the way: for single_result in $results ; do ....... I know I can increment a counter in my for loop, but would there be a way to know the total number of elements in... (4 Replies)
Discussion started by: gio001
4 Replies

9. Shell Programming and Scripting

How to extract elements using Awk

Hi, I have this typical extraction problem in AWK. I have 3 input files.. i) First one is somehow like an oracle of:- foo 12,23,24 bla 11,34 car 35 ii)Second file is basically detailing the score for each of the second field of first file. Besides, for the first column, it is the... (3 Replies)
Discussion started by: ahjiefreak
3 Replies

10. Shell Programming and Scripting

eval, array, number of elements - couldn't get it

I try to get a number of elements in an array, using dynamic array name. I need the array name to be dynamic. The array name is constructed as 'inf_ln_$nmb', where $nmb is a file line number So, say I have the arr 'inf_ln_4': > for (( el=0; el<${#inf_ln_4}; el++ )); do > echo "$el:... (1 Reply)
Discussion started by: alex_5161
1 Replies
Login or Register to Ask a Question