Hello all,
I am encountering some issue in trying to do the following in ksh88, therefore I want to explore a smart perl approach, but my knowledge is limited, can you help?
I have 2 files, the first (indexFile1) contains lines with start offset and length for each record inside the second file, so just 2 numbers separated by a space. The second file can be very large, each actual record start offset and length is defined by the entry in indexFile1. Since there are no records separators wc-l returns 0 for the second file, no matter how large its size actually is.
I want to gather all the records from the large file one at a time and write them out to a new file individually.
What is the best way to approach this processing?
I suspect I will have trouble in ksh88 reading a whole large file into a variable (using awk) and then use a cut command on the variable contents to collect my record in the form:
FileContent=$(awk '{print $0}' largeFile2) # this is where I think I h
+ave a problem :
# LINE contains start and offset identifying each record in largeFile2
while read LINE;do
pass=1
for results in $LINE; do
if [[ $pass -eq 1 ]];then
from=$results
pass=2
else to=$results
fi
done
(( from=$val1+1 ))
(( to=$val1+$val2 ))
newOut=$(echo $FileContent|cut -c $from-$to)
echo $newOut >> newfile
done < indexFile1
I have it working ok for small sizes of largeFile2. I can see a problem when the size of file2 gets large.
I hope you can give me some suggestions on how to do this better.
Thanks!
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.