Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cd to directory and how make it connected to for loop? 1

Status
Not open for further replies.

gargamel100

Technical User
Oct 25, 2006
31
CZ
Hi all,
using the line bellow
ls -l | awk ' { if ( $8~/^(0|1|2|3)/) print $8 }'
I have output like
01
02
03
04
05
06
07
08
09
10
11
12
and so on .... this is column which represent days of month.
I wish if it is possible using script that will cd 01 then in that directory do

d=`TZ=MET+24 date +%Y%m%d`
ls -l | awk ' { if ($8 ~ /^(aba)/) print $8 }' | wc -l >> top_$d.txt
wc -l *.cdr | grep total >> top_$d.txt
cd .. ( to main directory )
then cd 02 do again same and so on to cd 31 or ( 28 or 31 )
My question is how push code to do this

I have some ideas using for loop but I do not understant what to put as arguments inside for body.
If somebody know please write it down.

Regards
 
How about something like (for Korn shell):

for DIR in `ls -l | awk ' { if ( $8~/^(0|1|2|3)/) print $8 }'`
do
cd $DIR
d=`TZ=MET+24 date +%Y%m%d`
ls -l | awk ' { if ($8 ~ /^(aba)/) print $8 }' | wc -l >> top_$d.txt
wc -l *.cdr | grep total >> top_$d.txt
cd ..
done

I hope that helps.

Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top