Awk: can't open file!!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Awk: can't open file!!
# 1  
Old 06-05-2013
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.

Code:
for X in `ls /Users/misssmith/Desktop/birdseed/`; do awk '(NR==546412)' /Users/misssmith/Desktop/birdseed/$X >> /Users/misssmith/Desktop/birdseed/output.txt; done

in the command line. and keep getting the error: "awk:can't open file.." for each file in the folder.

permissions are: -rwxrwxrwx
and I can use awk on each individual file like this:

Code:
awk 'NR == 546412 {print}' /Users/misssmith/Desktop/birdseed/filename1.txt >> /Users/misssmith/Desktop/birdseed/output.txt

can anyone help?! please! thank you so much

Last edited by Scott; 06-05-2013 at 07:04 AM.. Reason: Code tags
# 2  
Old 06-05-2013
What are the permissions on the directory itself? It requires execute-level permission for whichever user is running the script.
# 3  
Old 06-05-2013
just checked. it's

drwxrwxrwx
# 4  
Old 06-05-2013
Code:
 
for X in /Users/misssmith/Desktop/birdseed/*
do
awk 'NR==546412' $X >> /Users/misssmith/Desktop/birdseed/output.txt
done

# 5  
Old 06-05-2013
dear pavrin27,

it is still throwing up the same error:

awk: can't open file file1.data.txt
source line number 1

---------- Post updated at 05:31 AM ---------- Previous update was at 05:28 AM ----------

oh my god, i am an idiot. problem solved. the file names i have have spaces in them so awk couldn't apparently open them. thank you!!
# 6  
Old 06-05-2013
Thanks for updating! So changing $X to "$X" should fix it.
This User Gave Thanks to Scott For This Post:
# 7  
Old 06-05-2013
Perhaps you can do the more efficient
Code:
for X in `ls /Users/misssmith/Desktop/birdseed/`; do
awk '(NR==546412)' /Users/misssmith/Desktop/birdseed/"$X"
done > /Users/misssmith/Desktop/birdseed/output.txt

And perhaps even
Code:
ls | xargs -i awk '(NR==546412)' /Users/misssmith/Desktop/birdseed/{} > /Users/misssmith/Desktop/birdseed/output.txt

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: 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

6. 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

7. 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

8. Shell Programming and Scripting

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... (3 Replies)
Discussion started by: jem43
3 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