Foreach .gz file in a directory -- Not working


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Foreach .gz file in a directory -- Not working
# 1  
Old 04-25-2014
Foreach .gz file in a directory -- Not working

Hi,

I am trying to add for loop in my code for all the .gz files in a directory.

example code:

Code:
for i in $PWD/input/*.dz
do
     echo " file is :: $i "
done

This is not working as expectation and the output is :
Code:
 file is :: /home/IB/input/*.dz



However, for i in $PWD/input/* is working fine. But this is not the requirement.
Please suggest

Moderator's Comments:
Mod Comment Use code tags, thanks.
# 2  
Old 04-25-2014
it will work.

Why you are using $PWD/input/*.dz
Code:
$PWD/input/*.dz

instead of
Code:
$PWD/input/*.gz

# 3  
Old 04-25-2014
that is typing mistake. I am using .gz
# 4  
Old 04-25-2014
What do you have in the variable PWD.
if echo $PWD gives you /home/IB
and still the code is not working, try below
Code:
for i in $(ls $PWD/input/*.gz)
do
  echo "file is :: ${i}"
done

# 5  
Old 04-25-2014
That is a useless use of ls *. If it works at all, it will work without the ls!

Code:
for i in $PWD/input/*.gz
do
  echo "file is :: ${i}"
done

Whenever a statement like that echoes "file is :: path/to/input/*.gz", that means, no files matched your expression, so doublecheck that you're looking where you think you are.
# 6  
Old 04-25-2014
Exactly!!!
It is working for me
Code:
for i in $PWD/input/*.gz
do
echo " file is :: $i "
done

Make sure your present working directory contains directory
Code:
input

in otherway make sure you are running script one directory back from
Code:
input

directory
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Reading foreach variable from a text file

Hello, I have a text file named "foreach.txt" which reads like --- foreach cal ( 1 2 3 4 5 ) I am using a simple script which looks like --- #!/bin/tcsh foreach cal (1 2 3 4 5) echo "$cal" end Is it possible to modify the script in such a way that instead of writing foreach cal (1... (6 Replies)
Discussion started by: Indra2011
6 Replies

2. Shell Programming and Scripting

PERL foreach & open not working together

My script is as below: my $tile_list = `egrep "FCFP_TILE_LIST.*=" ${BudgetDir}/tile.params | sed -e 's/FCFP_TILE_LIST//' | sed -e 's/=//'`; print "Tile List = ".$tile_list."\n"; my @tiles = split(/\s+/, $tile_list); $unconst_out = "${DestDir}/Unconstrained_ports.rpt"; $check_tim_out =... (2 Replies)
Discussion started by: kuchi7
2 Replies

3. UNIX for Dummies Questions & Answers

Foreach loop that skips the header line of a file (csh)

Hello all, I'm working on a foreach loop to compare a couple sets of data. However, each datafile includes a header row. I'm wondering if it is possible to tell the foreach loop to skip the first line of data. I've been using the basic code as follows: foreach line ("`file.csv`") set... (2 Replies)
Discussion started by: meteorologistks
2 Replies

4. Shell Programming and Scripting

foreach loop working in terminal but not in the script

Hi, I am new here I have used the forums a long time to search for things they are very helpful. I have unfortunately used up all my resources (professors, grad students) and need some help. I have this very simple piece of code (using to isolate the problem) in a csh script: #!/bin/csh... (12 Replies)
Discussion started by: bflinchum
12 Replies

5. Shell Programming and Scripting

put working directory in file

how to put pwd in my file my working directory is /usr/my_dir below my file aaaaaa bbbbbb so output file become /usr/my_dir aaaaaa bbbbbb (2 Replies)
Discussion started by: zulabc
2 Replies

6. Shell Programming and Scripting

Shell script: foreach file -> targzip

Hi there, I need some help with a shell script (I'm no sh script expert, but I hope this will explain how I want my script):dir = /home/user/files/ foreach(*.jpg file in $dir) { tar -cf $file(-.jpg).tar $file;gzip $file(-.jpg).tar } mv -f $dir*tar.gz /home/user/pictures/ Thanks for any... (12 Replies)
Discussion started by: JKMlol
12 Replies

7. HP-UX

how could I get process working directory

how could I use c program to get HP UX process working directory (1 Reply)
Discussion started by: alert0919
1 Replies

8. UNIX for Dummies Questions & Answers

working directory shown

Hi, How do I get my working directory always shown in the unix editor? i.e if I am now at /Home/abc/xyz/, I want to see this absolute path displayed ( and now only display when I type pwd). thanks for the kind help. Regrads (3 Replies)
Discussion started by: swchee
3 Replies

9. Programming

Getting present working directory

How can I get the present working directory in unix system using c programming and stored it in a string ?? (0 Replies)
Discussion started by: winsonlee
0 Replies
Login or Register to Ask a Question