AWK print initial record and double


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting AWK print initial record and double
# 1  
Old 09-20-2012
AWK print initial record and double

I have an initial record 0.018

I would like a script that would for i=0;i<200;i++ print
Code:
0.018*1
0.018*2
0.018*3
0.018*4
...
0.018*200

using newline.
# 2  
Old 09-20-2012
Which shell? Try:
Code:
for((i=1;i<=200;i++))
do
 echo '0.018*'$i
done

This User Gave Thanks to elixir_sinari For This Post:
# 3  
Old 09-20-2012
Korn shell if it's a bash script.

Also, your script doesn't work for me, I get

Code:
*0.018 0
*0.018 1
*0.018 2
*0.018 3
*0.018 4
*0.018 5
*0.018 6
*0.018 7
*0.018 8
*0.018 9
*0.018 10
*0.018 11
*0.018 12
*0.018 13
*0.018 14
*0.018 15
*0.018 16
*0.018 17
*0.018 18
*0.018 19

# 4  
Old 09-20-2012
What was the exact command you typed in?
# 5  
Old 09-20-2012
Code:
for((i=1;i<=200;i++))
do
 echo '0.018*'$i >> bla
done

with
Code:
ksh -x ./script

---------- Post updated at 06:54 AM ---------- Previous update was at 06:52 AM ----------

Ok, but now I get


Code:
0.018*1
0.018*2
0.018*3
0.018*4
0.018*5
0.018*6
0.018*7
0.018*8
0.018*9
0.018*10
0.018*11
0.018*12
0.018*13
0.018*14
0.018*15
0.018*16
0.018*17
0.018*18
0.018*19
0.018*20
0.018*21
0.018*22
0.018*23
0.018*24
0.018*25
0.018*26
0.018*27
0.018*28
0.018*29
0.018*30

How could I get the shell to actually evaluate the multiplication,

i.e. desired output

Code:
0.018
0.036
...

# 6  
Old 09-20-2012
pass it through either via expr or bc
# 7  
Old 09-20-2012
#!/bin/bash
Code:
for((i=1;i<=200;i++))
do
 foo=`expr 0.018\*$i`
 echo $foo >> bla
done


Gives

Code:
expr 0.018 \* $i
expr 0.018 \* $i
expr 0.018 \* $i
expr 0.018 \* $i
expr 0.018 \* $i
expr 0.018 \* $i
expr 0.018 \* $i
expr 0.018 \* $i
expr 0.018 \* $i
expr 0.018 \* $i
expr 0.018 \* $i
expr 0.018 \* $i
expr 0.018 \* $i
expr 0.018 \* $i

---------- Post updated at 07:34 AM ---------- Previous update was at 07:15 AM ----------

Ok, this works:

Code:
#!/bin/bash
for((i=1;i<=200;i++))
do
 echo "0.018 * $i" | bc
done

Code:
.018
.036
.054
.072
.090
.108
.126
.144
.162
.180
.198
.216
.234
.252
.270
.288
.306
.324
.342
.360
.378
.396
.414
.432
.450
.468
.486
.504
.522
.540

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk print matching records and occurences of each record

Hi all , I have two files : dblp.xml with dblp records and itu1.txt with faculty members records. I need to find out how many dblp records are related to the faculty members. More specific: I need to find out which names from itu1.txt are a match in dblp. xml file , print them and show how many... (4 Replies)
Discussion started by: iori
4 Replies

2. Shell Programming and Scripting

awk print - fields separated with comma's need to ignore inbetween double quotes

I am trying to re-format a .csv file using awk. I have 6 fields in the .csv file. Some of the fields are enclosed in double quotes and contain comma's inside the quotes. awk is breaking this into multiple fields. Sample lines from the .csv file: Device Name,Personnel,Date,Solution... (1 Reply)
Discussion started by: jxrst
1 Replies

3. Shell Programming and Scripting

awk to print record not equal specific pattern

how to use "awk" to print any record has pattern not equal ? for example my file has 5 records & I need to get all lines which $1=10 or 20 , $2=10 or 20 and $3 greater than "130302" as it shown : 10 20 1303252348212B030 20 10 1303242348212B030 40 34 1303252348212B030 10 20 ... (14 Replies)
Discussion started by: arm
14 Replies

4. Shell Programming and Scripting

How to compare current record,with next and previous record in awk without using array?

Hi! all can any one tell me how to compare current record of column with next and previous record in awk without using array my case is like this input.txt 0 32 1 26 2 27 3 34 4 26 5 25 6 24 9 23 0 32 1 28 2 15 3 26 4 24 (7 Replies)
Discussion started by: Dona Clara
7 Replies

5. Shell Programming and Scripting

[AWK script]Counting the character in record and print them in condition

.......... (1 Reply)
Discussion started by: Antonlee
1 Replies

6. Shell Programming and Scripting

AWK exclude first and last record, sort and print

Hi everyone, I've really searched for a solution to this and this is what I found so far: I need to sort a command output (here represented as a "cat file" command) and from the second down to the second-last line based on the second row and then print ALL the output with the specified section... (7 Replies)
Discussion started by: dentex
7 Replies

7. Shell Programming and Scripting

Print all the fields of record using awk

Hi, i want to generate print statement using awk. i have 20+ and 30+ fields in each line Now its priting only first eight fields print statement as output not all. my record is as shown below filename ... (2 Replies)
Discussion started by: raghavendra.nsn
2 Replies

8. Shell Programming and Scripting

awk - print record with both string1 and string2

How do I use awk to find the records in a file that contains two specific strings? I have tried piping and using awk two times, but I don't know how to do it in one action. (2 Replies)
Discussion started by: locoroco
2 Replies

9. Shell Programming and Scripting

awk - double quotes as record separator

How do I use double quotes as a record seperator in awk? (4 Replies)
Discussion started by: locoroco
4 Replies

10. UNIX for Advanced & Expert Users

Print Full record and substring in that record

I have i got a requirement like below. I have input file which contains following fixed width records. 00000000000088500232007112007111 I need the full record and concatenated with ~ and characters from 1to 5 and concatenated with ~ and charactes from 10 to 15 The out put will be like... (1 Reply)
Discussion started by: ukatru
1 Replies
Login or Register to Ask a Question