open files with multiple indexes


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting open files with multiple indexes
# 1  
Old 09-11-2012
open files with multiple indexes

Hi,

I want to work with multiple files which all contain 2 numbers.
I tried to make a nested for loop but for some reason it doesn't recognize the $j as a number. The output is cannot open file `175-T-pvalue.xls'. How do I make sure that it takes the numbers from the inner loop as $j?

Thanks!
Code:
for i in 148 162 171 174 175
do

	for j in 0.01 0.03 0.05 0.07 0.09
	do

		awk '/^chr/{cnt+=$4; num+=1} END{echo $i"Navg="(cnt/num)}' $i-N-pvalue$j_peaks.xls
		awk '/^chr/{cnt+=$4; num+=1} END{echo $i"Tavg="(cnt/num)}' $i-T-pvalue$j_peaks.xls
	done
done


Last edited by Franklin52; 09-11-2012 at 11:00 AM.. Reason: Please use code tags for data and code samples
# 2  
Old 09-11-2012
Are you trying to open microsoft excel file using awk ?

$i-N-pvalue$j_peaks.xls
# 3  
Old 09-11-2012
Further note: you cannot do much of anything with Excel files using awk.
You will need to get openoffice or star office on your UNIX box. Failing that, consider going into windows, saving each Excel file as a tab delimited .txt file. These work well with awk.
# 4  
Old 09-11-2012
Yes but thats not the problem.

If I run the following loop it does everything I want:

Code:
for i in 148 162 171 174 175
do
awk '/^chr/{cnt+=$4; num+=1} END{echo $i"Navg="(cnt/num)}' $i-N-pvalue0.01_peaks.xls
awk '/^chr/{cnt+=$4; num+=1} END{echo $i"Navg="(cnt/num)}' $i-N-pvalue0.02_peaks.xls
done

But I want to make an extra loop so I don't have to change the p-value from the filename every time..

Thanks!
Moderator's Comments:
Mod Comment
Please use code tags when posting data and code samples!


---------- Post updated at 11:28 AM ---------- Previous update was at 11:10 AM ----------

I already found it!

I needed to add \ \ because of the - in the filename

Last edited by vgersh99; 09-11-2012 at 12:16 PM.. Reason: once again - code tags, PLEASE!
# 5  
Old 09-11-2012
$j_peaks is not defined

try
Code:
awk '/^chr/{cnt+=$4; num+=1} END{echo $i"Navg="(cnt/num)}' $i-N-pvalue${j}_peaks.xls

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Adding indexes with PERL

Hello. I'm trying to self learn Perl and am stuck. I have a data.csv file that contains the following: 5,10,15,20,15,30 1,2,3,4,5 3,10 11 I'm trying to get Perl to take the indexes and add them all together to get 134. It says I need to use split and invoke the file via <> (built-in... (2 Replies)
Discussion started by: Eric7giants
2 Replies

2. Shell Programming and Scripting

I need to find out disk usage for particular indexes for different hosts

Need disk utilisation script for particular indexes on few hosts (3 Replies)
Discussion started by: Krish5v
3 Replies

3. UNIX for Advanced & Expert Users

Pass Multiple Commands and Open Multiple Xterms via PSS

Hello, I'm attempting to open multiple xterms and run a command as an SAP user via sudo using PSSH. So far, I'm able to run PSSH to a file of servers with no check for keys, open every xterm in to the servers in the file list, and SUDO to the SAP(ADM) user, but it won't do anything else... (11 Replies)
Discussion started by: icemanj
11 Replies

4. Programming

Control multiple program instances - open multiple files problem

Hello. This shouldn't be an unusual problem, but I cannot find anything about it at google or at other search machine. So, I've made an application using C++ and QtCreator. I 've made a new mime type for application's project files. My system (ubuntu 10.10), when I right click a file and I... (3 Replies)
Discussion started by: hakermania
3 Replies

5. UNIX for Dummies Questions & Answers

Using AWK: Extract data from multiple files and output to multiple new files

Hi, I'd like to process multiple files. For example: file1.txt file2.txt file3.txt Each file contains several lines of data. I want to extract a piece of data and output it to a new file. file1.txt ----> newfile1.txt file2.txt ----> newfile2.txt file3.txt ----> newfile3.txt Here is... (3 Replies)
Discussion started by: Liverpaul09
3 Replies

6. Shell Programming and Scripting

Perl, open multiple files with wildcards

I have a question regarding Perl scripting. If I want to say open files that all look like this and assign them to a filehandle and then assign the filehandle to a variable, how do I do this? The file names are strand1.fa.gz.tmp strand2.fa.gz.tmp strand3.fa.gz.tmp strand4.fa.gz.tmp ...... (6 Replies)
Discussion started by: japaneseguitars
6 Replies

7. Shell Programming and Scripting

matrix indexes

I wanted to use matrixs in awk and got some problem, here is some of the script code, from the BEGIN tag: row_char="a";row_char="b";row_char="c";row_char="d";row_char="e"$ row_char="h";row_char="i";row_char="j";row_char="k"; from the proccess passage: sentence,1]=1; diffrence=4; i=7;... (2 Replies)
Discussion started by: tal
2 Replies

8. Shell Programming and Scripting

Analyze the indexes and rebuild them

Hello UNIX and Oracle Gurus, After doing an intensive search from different websites, the UNIX forum I am posting this message seeking help.. I am trying to accomplish the following tasks through the shell script: 1. Rebuild indexes on a Table in Oracle 2. Analyze indexes and table... (0 Replies)
Discussion started by: madhunk
0 Replies

9. UNIX for Dummies Questions & Answers

using sed with indexes

Hi people, Is this possible and if so any tips are very welcome. Im trying to do the following: this is what I have: 800__1__ this is what I want: 8000010 12345678 Im... (1 Reply)
Discussion started by: seaten
1 Replies
Login or Register to Ask a Question