Breaking a text file on number of pages criteria in IFS.

435 pts.
Tags:
AS400 - STRQSH
IFS
Qshell
I have a text file on IFS which has 5500 pages and i want to break it in 1000 pages segments . Please suggest how can i accomplish this task ? Is there any unix or qshell command through which i can do this..

Software/Hardware used:
as400

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Discuss This Question: 10  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • TomLiotta
    i want to break it in 1000 pages segments .   How do you define a "page"? How do you tell when one page ends and the next page begins?   Tom
    125,585 pointsBadges:
    report
  • munduuu
    Tom: Either through form feed or *FCFC characters.
    435 pointsBadges:
    report
  • TomLiotta
    ...form feed or *FCFC characters.   That sounds like you had a large spooled file (5500 pages) that you ran CPYSPLF against. Then you copied the database file to a streamfile, and you want to break that streamfile into six parts.   To break it into parts, you will read lines from the file and count how many start with a '1' character. Whenever the count goes past 1000, you'll route your output to a new streamfile.   The uses of such a file might be few, but I suppose you have your reason.   I might come up with an ugly Qshell script using sed with a regular expression to find '1' at the start of a line, but it would be much more understandable just to read lines and copy them to another file. As soon as you count 1001, close the output file, open a new one and start writing again.   Java is probably easiest. After that, the ILE C APIs will be next easiest. Use fopen(), fgets(), fputs() and fclose(). They need to be coded in C, though, because they're implemented as C macros. However, if you look up the macros in the QSYSINC library, you can see how the macros translate into _C_IFS_fopen(), _C_IFS_fgets(), _C_IFS_fputs() and _C_IFS_fclose(), and those are procedure calls you can bind into any ILE language.   Overall, this seems like a complex bunch of code that has no known purpose. The logic problem is that only maybe every 50 to 60 lines will have a 'page' marker, and there is no guarantee that every page will have the same number of lines between those markers. There seems to be no good way around reading every line and counting markers.   But why are you doing it? Maybe there are better alternatives.   Tom
    125,585 pointsBadges:
    report
  • munduuu
    Thanks Tom ! Well actually we use common server to store reports and we have a requirement where client require a particular report in text format . Sometimes client ask for report in a single chunk and sometimes ask for segments with 1000 pages. We have a way to fetch full report and convert to text but for breaking in segments we don't. So i was wondering may be there is some qshell command with which we can break the text file on no. of pages criteria or some other approach .... 
    435 pointsBadges:
    report
  • TomLiotta
    One way of using Qshell would be to use the read utility to count lines and lines that start with '1'; every time 1000 pages are counted, echo the count out to standard out. Pipe the output into a sort to put it into reverse order by line count. Pipe that output into a small script that again uses read to grab the line counts one at a time, but it will start with the last one because it's sorted.   Subtract (1) from the count and put that value into the split utility using your original file. That will split off the very last group of lines into a separate file and put the rest into another new file.   Loop around and read the next count of lines and repeat.   Each time, you'll split off 1000 pages into a new file. You'll also generate a file that contains the lines from the first part of the file. You can use that in the next iteration of the loop.   See what you can come up with and we'll look it over.   I'd probably just write code using the C procedures, but you might find it easier to learn the Qshell utilities.   Tom
    125,585 pointsBadges:
    report
  • munduuu
    Hey Tom! thanks for your suggestion but i am little new to unix :( ..so can you please write the script for me so that i can understand it well. Frankly i am not able to form this script ... Thanks for your help!
    435 pointsBadges:
    report
  • philpl1jb
    Can you break it apart before you send it to the IFS?
    49,730 pointsBadges:
    report
  • munduuu
    Actually earlier we were using CPYF AND CPYTOIMF but some how there were some issues with CPYTOIMF command . So thought of generating full text file first and then breaking it .. 
    435 pointsBadges:
    report
  • TomLiotta
    ...we were using CPYF AND CPYTOIMF...   Assuming you mean CPYTOIMPF, it would probably not be the appropriate command. The CPYTOSTMF command is probably a better choice since this doesn't seem to be a database export function.   Tom
    125,585 pointsBadges:
    report
  • TomLiotta
    ...break it apart before you send it to the IFS?   Given the difficulties with doing after, I'd say that's the best way to go.   Tom
    125,585 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following