Copying some part of file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Copying some part of file
# 8  
Old 12-03-2008
Sorry for that, but if you check carefully my earlier query was actually confusing because of which i didn't get exactly what i wanted. Any ways, if its still a wrong-do then sorry once again
# 9  
Old 12-03-2008
Try this one:

Code:
awk '
/^EX ID/{i++;p=1}
/END EX ID/{p=0;print > "part"i".txt"}
p{print > "part"i".txt"}' file

Regards
# 10  
Old 12-03-2008
You may try something like this:
(use nawk or /usr/xpg4/bin/awk on Solaris)

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

# 11  
Old 12-03-2008
Duplicate of this post:

https://www.unix.com/shell-programmin...#post302263651

No duplicate or cross-posting, please read the rules.
# 12  
Old 12-03-2008
Code:
nawk '/EX ID : B-Mezine/{n++}
/^$/ { next}
{
	f=sprintf("%s.txt",n)
	print >> f
}' filename

# 13  
Old 12-03-2008
Quote:
Originally Posted by Franklin52
Duplicate of this post:

https://www.unix.com/shell-programmin...#post302263651

No duplicate or cross-posting, please read the rules.

Threads merged.
# 14  
Old 12-04-2008
Hey friends first of all thanx for putting efforts. :-)
I have tried Randoulov's solution as at a glance it is the only solution which has mentioned about 7700 records.
I.e.
awk '/^EX/ && !(i++%n) {
if (c) close(fn)
fn = ("part" ++c ".txt")
}
{ print > fn }
' n=7700


But I got following error

awk: A print or getline function must have a file name.
The input line number is 1. The file is test.txt.
The source line number is 5.



What may have gone wrong, can you please guide me?
Waiting for your reply. :-)
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