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!

Split 1 file (29000 recs) into 290 files (100 recs each)

Status
Not open for further replies.

YankeeJim

Programmer
Dec 12, 2002
8
US
Within a Unix shell script...

1) I have a large file and I want to split it into many smaller files (100 records each)...each with a different name (e.g INPT001, INPT002, INPT003, etc.).

2) I then want to process each file within a script loop and take the number of the file being processed and append it to output files to identify them.

Like:

1) within a loop...
mv 1st 100 records to INPT001
mv 2nd 100 records to INPT002
mv 3rd 100 records to INPT003
...and so on.

2) for file in INPT* # INPT001 - INPT290
do
mv INPT??? to INPT # INPT001
exec prog1
mv OUPT to OUPT??? # OUPT001
done

Thanks...
 
man split

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Sorry, my question is "How can I take the suffix from each file read and append it to each output file?"

I tried cut and paste...maybe I'm using it incorrectly.
 
Thanks, but that doesn't quite seem to do it.

I have three files (but there will be a lot more) named INPT001, INPT002, INPT003

My script is:

for file in INPT*
do
old=$file
echo "old file is " $old >> $JOBLOG
new="OUPT$(old#INPT)"
echo "new file is " $new >> $JOBLOG
done

and my output is:

old file is INPT001
new file is OUPT
old file is INPT002
new file is OUPT
old file is INPT003
new file is OUPT

What I want is:

old file is INPT001
new file is OUPT001
old file is INPT002
new file is OUPT002
old file is INPT003
new file is OUPT003

and what I REALLY want (also) is to isolate the 001 (002, 003, etc) into a local variable.

Thanks for your help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top