Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

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

Avatar of sunhux
sunhux asked on
Unix OSPerlShell Scripting
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
Avatar of zlobcho
zlobchoFlag of Germany image

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

Commented:
This problem has been solved!
Unlock 1 Answer and 6 Comments.
See Answers