awk Can't open file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk Can't open file
# 1  
Old 02-11-2010
Question awk Can't open file

Hello all,

I am creating a small bash script to cycle through some files that are the results of an analysis I have run (I am a statistician). There are many folders called job001, job002,...,job135. Each folder has a text file called results.txt. I want to create two summary files of the results - one which holds a list of ALL of the values in column 3 of every file, and one which checks the value in column 3 ( for all rows of all results files) and outputs the entire row if it is below a critical value. My code (for the first 2 folders - will change njobs to 135 when it works!):

Code:
njobs=2
crit=0.0000005
path="/Users/jm/"

for (( i=1;i<=$njobs;i++)); do
	jobnumber=$(printf "%03s" $i)  
	currentfile="${path}""job${jobnumber}"/results.txt
	echo $currentfile
	awk '$3<crit {print $0}' currentfile >> mhc_significant_results
	awk '{print $3}' currentfile >> lrt_pvals
	done

The echo $ currentfile prints out the correct filename & path. Results:

/Users/jm/job001/results.txt
awk: can't open file currentfile
source line number 1
awk: can't open file currentfile
source line number 1
/Users/jm/job002/results.txt
awk: can't open file currentfile
source line number 1
awk: can't open file currentfile
source line number 1

Can anyone suggest why the awk script can't seem to find and/or open the file? I suppose it's probably some misplaced or missing quotes or $ somewhere, but I can't spot it!

Many thanks in advance,
Jen
# 2  
Old 02-11-2010
Code:
	awk '$3<crit {print $0}' $currentfile >> mhc_significant_results
	awk '{print $3}' $currentfile >> lrt_pvals

# 3  
Old 02-11-2010
I think you are missing $ before the variable name.
Code:
 
 awk '$3<crit {print $0}' $currentfile >> mhc_significant_results
awk '{print $3}' $currentfile >> lrt_pvals

# 4  
Old 02-11-2010
Thanks, that's it! Silly me.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk can't open file; file merge attempt

Dear all, I have an AWK related issue. I have two data files; the first, FileA has fewer lines, the second, FileB has more. FileA is a subset of FileB . Both files are tab delimited. What I want to do? When the first two columns for FileA match the first two columns of FileB, I want to... (4 Replies)
Discussion started by: A_Human_Person
4 Replies

2. Shell Programming and Scripting

awk (Too many open files)

Hi Team, This is my first post, hope I am doing it right. I have a large file, like 6 GB. Its a proxy file so vendor requested to change username from logs for saving the confidentiality of the user. This is the script I created (With the help of Google): awk '{ tmp="echo " $5 " |... (12 Replies)
Discussion started by: tealc
12 Replies

3. Shell Programming and Scripting

awk output yields error: awk:can't open job_name (Autosys)

Good evening, Im newbie at unix specially with awk From an scheduler program called Autosys i want to extract some data reading an inputfile that comprises jobs names, then formating the output to columns for example 1. This is the inputfile: $ more MapaRep.txt ds_extra_nikira_usuarios... (18 Replies)
Discussion started by: alexcol
18 Replies

4. Shell Programming and Scripting

Awk: can't open error

Hi , In a directory i've the files in the following format pay:year:mon:11789604 pay:year:mon:17675644 --- and i need to get 4th part of the above file name so i used awk command in the below code #!/bin/ksh for test_data in pay* do txt_awk = awk -F':' '{print $4;}' $test_data ... (7 Replies)
Discussion started by: smile689
7 Replies

5. Shell Programming and Scripting

Awk: can't open file!!

To whom it may concern, Please help! I am trying to use awk to open all the files in a folder and remove one row and append everything into an output file. for X in `ls /Users/misssmith/Desktop/birdseed/`; do awk '(NR==546412)' /Users/misssmith/Desktop/birdseed/$X >>... (6 Replies)
Discussion started by: salpie
6 Replies

6. Shell Programming and Scripting

Awk: cannot open file (No such file or directory)

Hello folks! I am new to Shell and awk scripting. This is my shell script that receives a string as an input from the user from the stdin. #!bin/sh printf "Enter your query\n" read query cmd=`echo $query | cut -f 1 -d " "` input_file=`echo $query | cut -f 2 -d " "` printf $input_file... (10 Replies)
Discussion started by: radiohead_
10 Replies

7. Shell Programming and Scripting

awk: can't open the file

I have a shell script with the following awk command. awk '$1 == "GEOG_SRV"{split($2,a,":");print a}' /etc/qm when I run it manually command line its fine and giving the output. bash-3.00$ awk '$1 == "GEOG_SRV"{split($2,a,":");print a}' /etc/qm 9010 But in the script its... (5 Replies)
Discussion started by: Tuxidow
5 Replies

8. Red Hat

cannot set user id: Resource temporarily unavailable (not open file/open process related)

First post, sorry to be a bother but this one has been dogging me. I have a process user (java application server) that trips a resource limit every couple weeks and need help finding what limit we're hitting. First, this is what's running: This is the error when jobs are run or the... (0 Replies)
Discussion started by: Katahdin
0 Replies

9. Shell Programming and Scripting

awk: can't open

Hi Guys, I was just trying to run a bunch of test scripts which ran perfectly before i changed servers to a different solaris machine. But i just changed it to run on a different solaris version and my awk statement in the script shows an error. awk BEGIN{s=ARGV; r=ARGV; \ ... (2 Replies)
Discussion started by: wick3dsunny
2 Replies

10. Shell Programming and Scripting

awk: cannot open inputf

I'd like some help with awk too. Somewhere in my bash script i have written something like this: awk -v outputfile=$finalFile -v inputf=$file 'BEGIN { commands } { more commands } ΕND{ }' inputf where the file is a .input file with data. I also tried this: awk -v... (2 Replies)
Discussion started by: little_fairy
2 Replies
Login or Register to Ask a Question