Copying some part of file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Copying some part of file
# 15  
Old 12-04-2008
OK,
try this:

Code:
awk '/^EX/ && !(i++%n) { 
  if (c) close(fn)
  fn = ("part" ++c ".txt")
  }  
fn { print > fn }
' n=7700 infile

# 16  
Old 12-04-2008
Dear Randoulov,
Thanx for the reply, i have tried it on my system, but it is giving following errorSmilie

vxfs: msgcnt 132 mesg 001: V-2-1: vx_nospace - /dev/report/lv_report file system full (1 blo
k extent)


Also, the file is not gettig terminated at END EX ID Smilie

please can you spare some time to solve this problem Smilie

Anushree A
# 17  
Old 12-04-2008
Quote:
Originally Posted by anushree.a
Dear Randoulov,
Thanx for the reply, i have tried it on my system, but it is giving following errorSmilie

vxfs: msgcnt 132 mesg 001: V-2-1: vx_nospace - /dev/report/lv_report file system full (1 blo
k extent)
Well,
this is because you run out of space. You should consider using a different filesystem for this operation, if there is not enough space on the current one.

Quote:
Also, the file is not gettig terminated at END EX ID Smilie
[...]
Could you post a sample data from such a file?
# 18  
Old 12-05-2008
Yes buddy,

Here it is,

EX ID : B-Mezine Body Language (Tto Order Q=14)
Prmnt Tto: 6
Avg size: 2.07 Sq Inch
Ext loctn: Lower Back
Mono Ink code: 174
Color ink code: 132, 111, 202
Sff: 1.04 mg
SX: F
Age: 19
Artist: Ankita
Artist Code: AKT_Mum_Colaba
Dt: 07272008 00:02
DDt: 08072008
END EX ID


EX ID : B-Mezine Body Language (Tto Order Q=15)
Prmnt Tto: 6
Avg size: 3.00 Sq Inch
Ext Loctn: Arnd Belly Button
Mono Ink code: 174
Color ink code: None
Sff: 2.41 mg
CrcM: 12 mns
Dr: none
Pn: Brb
Status: Healing
SX: F
Age: 23
EDrtn: 1:30 Approx
Artst: Ankita
Artist Code: AKT_Mum_Colaba
Dt: 07272008 07:16
DDt: 08072008
END EX ID

EX ID : B-Mezine Body Language (Piercing Order Q=15)
Piercing: 2
Ext Loctn: Belly Button
Mono Ink code: None
Color ink code: None
CrcM: 10 mns
Dr: Shamila
Pn: Brb
Status: Healing
SX: F
Age: 24
Artst: Anushree
Artist Code: ANS_Mum_Colaba
Dt: 07282008 12:23
DDt: 08082008
END EX ID

Dear you can notice the length of each record (Text from EX ID : B-Mezine to END EX ID) is not fixed. In first record its 14 lines, 2nd record its 19 lines.
# 19  
Old 12-05-2008
I cannot reproduce the issue with the above sample.
Is the output below correct?

Code:
$ cat file
EX ID : B-Mezine Body Language (Tto Order Q=14)
Prmnt Tto: 6
Avg size: 2.07 Sq Inch
Ext loctn: Lower Back
Mono Ink code: 174
Color ink code: 132, 111, 202
Sff: 1.04 mg
SX: F
Age: 19
Artist: Ankita
Artist Code: AKT_Mum_Colaba
Dt: 07272008 00:02
DDt: 08072008
END EX ID


EX ID : B-Mezine Body Language (Tto Order Q=15)
Prmnt Tto: 6
Avg size: 3.00 Sq Inch
Ext Loctn: Arnd Belly Button
Mono Ink code: 174
Color ink code: None
Sff: 2.41 mg
CrcM: 12 mns
Dr: none
Pn: Brb
Status: Healing
SX: F
Age: 23
EDrtn: 1:30 Approx
Artst: Ankita
Artist Code: AKT_Mum_Colaba
Dt: 07272008 07:16
DDt: 08072008
END EX ID

EX ID : B-Mezine Body Language (Piercing Order Q=15)
Piercing: 2
Ext Loctn: Belly Button
Mono Ink code: None
Color ink code: None
CrcM: 10 mns
Dr: Shamila
Pn: Brb
Status: Healing
SX: F
Age: 24
Artst: Anushree
Artist Code: ANS_Mum_Colaba
Dt: 07282008 12:23
DDt: 08082008
END EX ID

$ nawk '/^EX/ && !(i++%n) {
  if (c) close(fn)
  fn = ("part" ++c ".txt")
  }
{ print > fn }
' n=2 file
$ head -200 part*
==> part1.txt <==
EX ID : B-Mezine Body Language (Tto Order Q=14)
Prmnt Tto: 6
Avg size: 2.07 Sq Inch
Ext loctn: Lower Back
Mono Ink code: 174
Color ink code: 132, 111, 202
Sff: 1.04 mg
SX: F
Age: 19
Artist: Ankita
Artist Code: AKT_Mum_Colaba
Dt: 07272008 00:02
DDt: 08072008
END EX ID


EX ID : B-Mezine Body Language (Tto Order Q=15)
Prmnt Tto: 6
Avg size: 3.00 Sq Inch
Ext Loctn: Arnd Belly Button
Mono Ink code: 174
Color ink code: None
Sff: 2.41 mg
CrcM: 12 mns
Dr: none
Pn: Brb
Status: Healing
SX: F
Age: 23
EDrtn: 1:30 Approx
Artst: Ankita
Artist Code: AKT_Mum_Colaba
Dt: 07272008 07:16
DDt: 08072008
END EX ID


==> part2.txt <==
EX ID : B-Mezine Body Language (Piercing Order Q=15)
Piercing: 2
Ext Loctn: Belly Button
Mono Ink code: None
Color ink code: None
CrcM: 10 mns
Dr: Shamila
Pn: Brb
Status: Healing
SX: F
Age: 24
Artst: Anushree
Artist Code: ANS_Mum_Colaba
Dt: 07282008 12:23
DDt: 08082008
END EX ID

# 20  
Old 12-08-2008
Yes buddy that is exactly what i wanna do. Only diff is, in part1.txt u hv taken 2 records, instead of it, it will have first 7700 records.. next 7700 records will b in part2.txt and so on.
# 21  
Old 12-08-2008
That's clear, ant changing n=2 to n=7700 should do it ...
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