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

Catting to make one file

Status
Not open for further replies.

maxcrook

Programmer
Jan 25, 2001
210
GB
I have 10 files all called file1, file2, file3 etc

I need to automate the process so that the following can be done automatically.

I start with the highest numerical file number and cat that to the next highest in sequence, then remove the highest like so......

cat file10 >> file 9
rm file10
cat file9 >> file8
rm file9
etc..............
Is there an easy way to do this ?

So far i have tried several ways and each one deletes the end file created - file1!

Help me please I am losing the will to live !
 
x=10
while [ "$x" -ne "1" ] ; do
y=`echo "$x-1"|bc`
cat $x >>$y
rm $x
x=$y
done
 
Thanks,I tried running this and the message:

cat: 0652-050 Cannot open 10.

was displayed. Also files are called file_1 not file1 sorry.

Max

 
I created 10 files called "1" thru "10" for testing.

Change the 3rd line of the script to be "cat file_$x >> file_$y". Change the 4th line to read "rm file_$x". This should fix your problems.

Bill.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top