Copying some part of file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Copying some part of file
# 1  
Old 12-02-2008
Copying some part of file

Hey friends,
Here I am with another query. I have a TXT file.
Foe an example

EX ID : B-Mezine
....
...
...
Some lines of text (Not fixed in length n no of lines)..
...
...
..

END EX ID

Some blank lines in between two records(Not fixed in numbers)

EX ID : B-Mezine
....
...
...
Some lines of text (Not fixed in length n no of lines)
..
...
...
..
END EX ID
Some blank lines in between two records(Not fixed in numbers)
EX ID : B-Mezine
....
...
...
Some lines of text (Not fixed in length n no of lines)
..
...
...
..
END EX ID


Now if I consider portion from EX ID : B-Mezine to END EX ID a record then this file has some thousand record in it.

Now what I want is, I want to split this file in say 7700 records in each file. For eg. If a file has 38700 records and I want to split this file in 7700-7700 records then it should copy first 7700 records from the main file n paste it in a new file named as part1.txt, den next 7700 records-part2.txt n so on.

Can any one help me in this matter?

Thanx in advance
Anushree.
# 2  
Old 12-02-2008
Question Clarification on records vs. lines

In your example, you show many lines but three records. So, are you saying that the file hase 38500 records configured as your examples, and you want to make five 7700 record files from this?
# 3  
Old 12-02-2008
dear Joeyg,
Input file 38700 regords in the format which i hv illustrated (my format shows 3 records, but in actual input file there are 38700 records which I want to split in 1-7700 records in 1st file (o/p File name part1.txt), 7701-15400 in 2nd file (o/p File name part2.txt), 15401-23100 in 3rd file (o/p File name part3.txt) and so on.
# 4  
Old 12-02-2008
Try this:

Code:
awk 'NR%7700==1 {i++} {print > "part"i".txt"}' file

Regards
# 5  
Old 12-03-2008
Thanx for the solution buddy,
But it is splitting the file on the basis of number of lines i.e. 7700 lines in each o/p file, which is not i am looking for. I have an input file which has around 35,500 number of records which starts by the pattern "EX ID : B-Mezine" and consists some data which is not fixed in lenght n number of lines, and after that it ends with pattern "END EX ID" and this is called as "A Record"

The script ideally should pick 7700 records from input file, write it to out put file named as part1.txt, then next 7700 records, writes it to o/p fil named as part2.txt nso on.

Waiting for your reply anxiously
Please...
Anushree A
# 6  
Old 12-03-2008
please help. Dividing a file.

Hey friends,
Here I am with another query. I have a TXT file.
Foe an example

EX ID : B-Mezine
....
...
...
Some lines of text (Not fixed in length n no of lines).....
...
..
END EX ID

Some blank lines in between two records(Not fixed in numbers)

EX ID : B-Mezine
....
...
...
Some lines of text (Not fixed in length n no of lines)
..
...
...
..END EX ID

Some blank lines in between two records(Not fixed in numbers)
EX ID : B-Mezine
....
...
...
Some lines of text (Not fixed in length n no of lines)
..
...
...
..END EX ID

The portion EX ID : B-Mezine to END EX ID makes a RECORD

Now if I consider portion from EX ID : B-Mezine to END EX ID a record then this file has some thousand record in it.

Now what I want is, I want to split this file in say 7700 RECORD (Not lines) in each file. For eg. If a file has 38700 records and I want to split this file in 7700-7700 records then it should copy first 7700 records from the main file n paste it in a new file named as part1.txt, den next 7700 records-part2.txt n so on.

Can any one help me in this matter?

Thanx in advance
Anushree.
# 7  
Old 12-03-2008
Respect the forum rules:

Code:
(4) Do not 'bump up' questions if they are not answered promptly. No duplicate or cross-posting and do not report a post or send a private message where your goal is to get an answer more quickly.

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to make a loop to read the input from a file part by part?

Hi All, We've a VDI infrastructure in AWS (AWS workspaces) and we're planning to automate the process of provisioning workspaces. Instead of going to GUI console, and launching workspaces by selecting individual users is little time consuming. Thus, I want to create them in bunches from AWS CLI... (6 Replies)
Discussion started by: arun_adm
6 Replies

2. Shell Programming and Scripting

Copying a file to multiple other files using a text file as input

Hello, I have a file called COMPLIST as follows that contains 4 digit numbers.0002 0003 0010 0013 0015 0016 0022 0023 0024 0025 0027 0030 0031 0032 0033 0035 0038 0041 (3 Replies)
Discussion started by: sph90457
3 Replies

3. UNIX for Dummies Questions & Answers

Renaming files with part of their pathname and copying them to new directory

Hi I think this should be relatively simple but I can't figure it out. I have several files with the same name in different folders within a directory (the output of a program that I ran). Something like this: ./myAnalysis/item1/round1/myoutput.txt ./myAnalysis/item1/round2/myoutput.txt... (2 Replies)
Discussion started by: jullee
2 Replies

4. UNIX for Dummies Questions & Answers

Copying part of a data file into another

Hi, I have a large number of data files each containing simple integers from 1 to around 25000 in ascending order. However, they are not in a specific progression; some numbers are missing in each file. For ex. datfile1 may have the numbers in order 1 2 4 6 7 8 12 ... 24996 24999 while datfile2... (8 Replies)
Discussion started by: latsyrc
8 Replies

5. Shell Programming and Scripting

[Solved] Printing a part of the last line of the specific part of a file

Hi, I have 80 large files, from which I want to get a specific value to run a Bash script. Firstly, I want to get the part of a file which contains this: Name =A xxxxxx yyyyyy zzzzzz aaaaaa bbbbbb Value = 57 This is necessary because in a file there are written more lines which... (6 Replies)
Discussion started by: wenclu
6 Replies

6. UNIX for Dummies Questions & Answers

Help with searching for a file in a directory and copying the contents of that file in a new file

Hi guys, I am a newbie here :wall: I need a script that can search for a file in a directory and copy the contents of that file in a new file. Please help me. :confused: Thanks in advance~ (6 Replies)
Discussion started by: zel2zel
6 Replies

7. Shell Programming and Scripting

sed command for copying the contents of other file replacing it another file on specifc pattern

We have 2 file XML files - FILE1.XML and FILE2.xml - we need copy the contents of FILE1.XML and replace in FILE2.xml pattern "<assignedAttributeList></assignedAttributeList>" FILE1.XML 1. <itemList> 2. <item type="Manufactured"> 3. <resourceCode>431048</resourceCode> 4. ... (0 Replies)
Discussion started by: balrajg
0 Replies

8. UNIX for Dummies Questions & Answers

Copying one file into another

I have two files, lets say file1.pun and file2.pun Now i need to copy the first 10 lines of file1.pun and paste them on the head of file2.pun without deleting the contents of file2.pun. I have to do this from command line only. Can u plz guide me in this regards (4 Replies)
Discussion started by: jasjot31
4 Replies

9. Filesystems, Disks and Memory

Strange difference in file size when copying LARGE file..

Hi, Im trying to take a database backup. one of the files is 26 GB. I am using cp -pr to create a backup copy of the database. after the copying is complete, if i do du -hrs on the folders i saw a difference of 2GB. The weird fact is that the BACKUP folder was 2 GB more than the original one! ... (1 Reply)
Discussion started by: 0ktalmagik
1 Replies

10. Shell Programming and Scripting

copying the csv file into different worksheets of xls file

Hi, I have a script which will generate three csv files. i want to copy the contents of these csv files into a .XLS file but in different worksheets. Can a this be done in the same script? :confused: Can Perl come to my help in coping the csv files into different worksheets of .XLS file ?... (0 Replies)
Discussion started by: nimish
0 Replies
Login or Register to Ask a Question