adding one more column in a loop


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting adding one more column in a loop
# 1  
Old 10-22-2012
adding one more column in a loop

Code:
data1
1 0.01 3 5
1 0.6  2 1
 
data2
2 0.02 3 5
2 0.3 2 1
 
data3
3 0.01 3 5
3 0.01 2 1
 
output 
 
1 0.01 data1
2 0.02 data2
3 0.01 data3
3 0.01 data3

I want to print 1st, 2nd column and the filename when second column is less than 5.

I have tried
Code:
for i in data1 data2 data3
gawk '{if ($2 < 0.05) print $1, $2, ${i}}' > ${i}
done
 
cat data1 data2 data3 > output

but i dont think ${i} part works. any idea?

Last edited by Scott; 10-22-2012 at 06:19 PM.. Reason: Code tags
# 2  
Old 10-22-2012
Try:
Code:
 
gawk '{if ($2 < 0.05) print $1, $2, FILENAME}' > ${i}

This User Gave Thanks to rdrtx1 For This Post:
# 3  
Old 10-22-2012
awesome thanks!
# 4  
Old 10-22-2012
Quote:
Originally Posted by rdrtx1
Try:
Code:
 
gawk '{if ($2 < 0.05) print $1, $2, FILENAME}' > ${i}

A slight variation to force the numeric conversion:
Code:
awk '$2+0<0.05{print $1,$2,FILENAME}' data*

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Adding values of a column based on another column

Hello, I have a data such as this: ENSGALG00000000189 329 G A 4 2 0 ENSGALG00000000189 518 T C 5 1 0 ENSGALG00000000189 1104 G A 5 1 0 ENSGALG00000000187 3687 G T 5 1 0 ENSGALG00000000187 4533 A T 4 2 0 ENSGALG00000000233 5811 T C 4 2 0 ENSGALG00000000233 5998 C A 5 1 0 I want to... (3 Replies)
Discussion started by: Homa
3 Replies

2. Shell Programming and Scripting

Download images from the first column and rename it with the second column in a loop: Please help!

Dear Friends, I have a very little knowledge on shell scripting. I am stuck with a problem for which I need an expert advice. I have a .txt file "image_urls.txt" which contains the data like this imageurl ... (2 Replies)
Discussion started by: Praveen Pandit
2 Replies

3. Shell Programming and Scripting

Adding a while loop to my script

I have a script below that goes to the given directory and plays the newest powerpoint presentation via powerpoint viewer and wine. So far it works perfectly but now Id like to add a while statement to essentially run find /ticker/powerpointshare -mmin -1 -type f -iname "*.ppt" and if it finds a... (9 Replies)
Discussion started by: binary-ninja
9 Replies

4. UNIX for Dummies Questions & Answers

Rename a header column by adding another column entry to the header column name

Hi All, I have a file example.csv which looks like this GrpID,TargetID,Signal,Avg_Num CSCH74_1_1,2007,61,256 CSCH74_1_1,212007,647,679 CSCH74_1_1,12007,3,32 CSCH74_1_1,207,299,777 I want the output as GrpID,TragetID,Signal-CSCH74_1_1,Avg_Num CSCH74_1_1,2007,61,256... (1 Reply)
Discussion started by: Vavad
1 Replies

5. Shell Programming and Scripting

Rename a header column by adding another column entry to the header column name URGENT!!

Hi All, I have a file example.csv which looks like this GrpID,TargetID,Signal,Avg_Num CSCH74_1_1,2007,61,256 CSCH74_1_1,212007,647,679 CSCH74_1_1,12007,3,32 CSCH74_1_1,207,299,777 I want the output as GrpID,TragetID,Signal-CSCH74_1_1,Avg_Num CSCH74_1_1,2007,61,256... (4 Replies)
Discussion started by: Vavad
4 Replies

6. Shell Programming and Scripting

loop in awk - column max for each column

Hello all, this should really be easy for you... I need AWK to print column maxima for each column of such input: Input: 1 2 3 1 2 1 1 3 2 1 1 2 Output should be: 2 2 3 3 This does the sum, but i need max instead: { for(i=1; i<=NF; i++) sum +=$i } END {for(i=1; i in sum;... (3 Replies)
Discussion started by: irrevocabile
3 Replies

7. Shell Programming and Scripting

Adding column

Hello, I'm struggling with the following problem in sh script: Adding a column to the right-end of a file ("master-file": non-constant column number, tab and linux formatted) where the column is the 4th one of file1 (space and DOS formatted) Changing the header of column 4 of file 1 at the... (4 Replies)
Discussion started by: lco
4 Replies

8. Shell Programming and Scripting

doing a for loop adding up the results

Hi there If I run a 'swap -l' on my solaris box, i get swapfile dev swaplo blocks free /dev/dsk/c1t0d0s1 54,65 8 67119560 65655144 /dev/dsk/c1t0d0s2 54,65 8 33119522 32655122 I wanted to run a for loop adding up the totals of each column 4 , excluding the... (2 Replies)
Discussion started by: hcclnoodles
2 Replies

9. Shell Programming and Scripting

adding values with a loop

Hi there, I am checking disk spaced used on a box # df -k | grep dsk | awk {'print $3'} 2055463 20165785 18310202 32274406 I want to somehow add them up but am no quite sure how to do this in a loop. ...i.e for n in 'df -k | grep dsk | awk {'print $3}' do <some adding... (1 Reply)
Discussion started by: hcclnoodles
1 Replies

10. Programming

adding variables for, for loop

I have a structure which contains n number of elements. For example: stFruits : apple, grapes, strawberry, pear, kiwi, melon, papaya, mango, orange, sweetlime ..... etc Now i have to write a for loop as follows: int i; int j; j=stFruits.apple+stFruits.grapes+stFruits.pear+.... and so... (3 Replies)
Discussion started by: jazz
3 Replies
Login or Register to Ask a Question