0

I have temp.xml file with below contents,

   <records>
      <profile/>
      <profile/>
      <profile/>
      <profile/>
      .
      .
    </records>

I will pass the number of records,'n', as the input. I want the temp.xml file to be split into 'n' number of records. For eg., if I have 4 records in temp.xml and if I pass n value as 2, then 2 files has to be created with 2 records each.

The output file name can be anything. For eg., below is the sample output. where 4 records are split into 2 files with 2 records (profile). Records count should be consistent.

temp1.xml
<profile/>
<profile/>

temp2.xml
<profile/>
<profile/>
3
  • What if total record count in file is not divisible by n? Commented Jan 7, 2016 at 7:15
  • use awk, set RS='<profile' & based on n passed & NR value, change the output file name. Commented Jan 7, 2016 at 7:16
  • last file should contain remaining recods, for eg: temp.xml will have 13 records and split size is 2 then 6 file with 2 records and 7th file will contain 1 record. Commented Jan 7, 2016 at 7:17

1 Answer 1

2

i have splited the file using below command

split -l 3 -a 2 temp.xml remp.xml_

-a 2 :will be used to create file name like temp.xml_aa, temp.xml_ab

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.