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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

RETURNING NO. OF FILES COUNT

Status
Not open for further replies.

dayankoven

Programmer
Oct 28, 2002
17
MY
Hi there fellow gurus,

I have 3 files in the directory.
Test_Append_Time20021011123500.DAT
Test_Append_Time20021011123501.DAT
Test_Append_Time20021011143500.DAT


I'm written a script that will scan a directory looking for files with particular pattern ("Test_Append_Time") and replace "Test_Append_Time" with 1001. The end result will look like:-
100120021011123500.DAT
100120021011123501.DAT
100120021011143500.DAT

Once i've done that, I need to sum up the total number,X of records that is 1001*00 and also total number,Y which is 1001*01. Then i need to do a computation for Z = X+Y-1. Then i need to return Z which in this case would total "2" back.

I've managed to list the total X and Y on the screen but don't know how to store them in variable/strings. Can fellow forummers please help me..? Thanks in advance
My code looks something like :-

#!/usr/bin/sh

oldPREF="Test_Append_Time"
newPREF="1001"

for file in ${oldPREF}*
do
mv "${file}" "${newPREF}${file#${oldPREF}}"

ls ${newPREF}*00.DAT|grep -v '^d|^total'| wc -l
ls ${newPREF}*01.DAT|grep -v '^d|^total'| wc -l

done






 
Possibly something like:

total1=`ls ${newPREF}*00.DAT|grep -v '^d|^total'| wc -l`
total2=`ls ${newPREF}*01.DAT|grep -v '^d|^total'| wc -l`

Where the ` are backticks (above the tab key on most keyboards). HTH.
 
hi,
it depends a little from OS and shell type;
however try by

var=$(command)

or, for the backquoted version, use:

var=`command`

BYE
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top