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

Catting then deleting 1

Status
Not open for further replies.

maxcrook

Programmer
Jan 25, 2001
210
GB
I start with 10 files called file_8_123_1, file_8_124_1, file_8_125_1, file_8_126_1.....etc etc.

I need to cat these files together starting with the higest number file being catted to the next highest in sequence then being deleted
eg.
Above would be

cat file_8_126_1 >> file_8_125_1
rm file_8_126_1
cat file_8_125_1 >> file_8_124_1
rm file_8_125_1
etc etc

I need a script where the user inputs the highest file number (the only number that changes is the 123 above) and the lowest number so that the script knows at what point to stop deleting the files and where to start.

Any solutions out there ?
 
Here's the basic principle (I think). It works but may need some improvement to suit your needs.

Code:
#!/bin/ksh

echo enter low:
read LOW
echo enter high:
read HIGH
CATFROM=$HIGH
CATTO=`expr $HIGH - 1`

echo CATFROM=$CATFROM CATTO=$CATTO

while [ $CATTO -ge $LOW ]
do
  cat file_8_${CATFROM}_1 >> file_8_${CATTO}_1

  rm file_8_${CATFROM}_1

  CATFROM=`expr $CATFROM - 1`
  CATTO=`expr $CATTO - 1`
done

echo Finished

Greg.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top