troubleshooting Question

Unix Shell or Perl script to facilitate splitting a file based on a footer separator

Avatar of sunhux
sunhux asked on
Shell ScriptingPerlUnix OS
6 Comments1 Solution330 ViewsLast Modified:

I currently have to use editor to manually split a file & would like a script to faciliate
the splitting such I can just run :
./splitting_script  Inputfile


There's a separator that tells us where to split the Inputfile.
A file with 3 separators will be split into 3 files,
a file with n separators will be split into n files.
Eg of an Inputfile:
record1 .....
record2 .....
...............
recordX
<YYYYMMDDhhmm_abcd>      <== this is a separator
recordX+1
........
recordY
<YYYYMMDDhhmm_abcd>      <== this is another separator
recordY+1
........
recordZ
<YYYYMMDDhhmm_abcd>      <== this is the last separator

where YYYYMMDD is the numeric date, hhmm is hour_minute
while abcd is a variable number (can be a 3 or 4 or 5 digit number).

Since the date, time & variable number are non-constant,
  the  <......>  is the separator to look for.


So in the above example, the InputFile would be split into the 3 files below :
File1:
====
record1 .....
record2 .....
...............
recordX
<YYYYMMDDhhmm_abcd>

File2:
====
recordX+1
........
recordY
<YYYYMMDDhhmm_abcd>

File3:
====
recordY+1
........
recordZ
<YYYYMMDDhhmm_abcd>


ASKER CERTIFIED SOLUTION
zlobcho

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 6 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros