Help on Spliting files - urgent


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help on Spliting files - urgent
# 8  
Old 03-10-2008
Bug Re:Help on Splitting files

Hi Rad
Thanks for the explanation of the code. I have made few changes just for the readability of the code. Hope I have done the changes correctly.Also I would like to know how x[length] automatically resets to 0 everytime when the length of the digit changes .for eg.if the numbers are 23,45,56,234 then x[length] is 1,2,3 and then 1 again.. I understood the rest of the code.

nawk 'BEGIN {
n=split("a b c d e f g h i j k l m n o p q r s t u v w x y z",f)
c2=c1=c=1
}
{
if (x[length] % 5 == 0)
{
close(fn);
fn="cin"f[c2]f[c1]f[c]".in"
if ((c1==n) && (c==n))
c2=c2>=n?1:++c2

c=c>=n?1:++c

if (c==1)
c1=c1>=n?1:++c1
}
x[length]=x[length] + 1
}
{ print > fn }' cin.in
# 9  
Old 03-10-2008
Quote:
Originally Posted by rajee
[...]
Also I would like to know how x[length] automatically resets to 0 everytime when the length of the digit changes .for eg.if the numbers are 23,45,56,234 then x[length] is 1,2,3 and then 1 again..
[...]
Yes,
consider the following:

Code:
$ print '1
22
22
22
333
333
4444
4444'|nawk '{print $1,x[length]++}'
1 0
22 0
22 1
22 2
333 0
333 1
4444 0
4444 1
$

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

XML spliting

hi, Am able to split an XML file by using follwing awk command, awk 'NR==1{x=$0;next}/<\/Order>/{print y RS $0 RS "</Order>">f}/Order BillToKey/{f="file"++n".xml";y=x}{y=y RS $0}' filename.xml but i need to insert a following tag in the begining of every file how to do so. The tag is as... (7 Replies)
Discussion started by: mitnix
7 Replies

2. Shell Programming and Scripting

Spliting log file

Hello, I want to split or cut a large size log file by year wise(eg 2009, 2010) .But the source file must not have the splited or cut lines after this process ,all of them must move to the destination folder.Does grep command have the fuctionality like cut and paste? I used grep -Ev command but... (17 Replies)
Discussion started by: jobycxa
17 Replies

3. UNIX for Dummies Questions & Answers

Zipping files - Please help me its urgent

Dear all, I have thousands of log files in my log directory which I need to zip them and archive. I tried using zip command. But it is not allowing me to archive it more that 4GB of file size. So how to archive them. If it is not possible how to zip all files in to multiple archive files which... (3 Replies)
Discussion started by: tvbhkishore
3 Replies

4. UNIX for Dummies Questions & Answers

Spliting of two files

hi I have a log file which contains some reports. The log file looks like this:- STARTOFREPORT /tmp file1.txt some text to be folowd ENDOFREPORT some non utilized characters STARTOFREPORT /log file2.txt more text (3 Replies)
Discussion started by: infyanurag
3 Replies

5. Shell Programming and Scripting

spliting up a large file

Dear All, I have a very large file which which i would like split into indvidual frames evrytime the line ends with "ENDMDL" and then name frame1.pdb frame2.pdb etc can any one give me a few sugeestions? ideally i would like to have ENDMDL at the end of each frame or not pressent at all. an... (4 Replies)
Discussion started by: Mish_99
4 Replies

6. UNIX for Dummies Questions & Answers

spliting a file

how would i split the file "file1" into smaller files containg lines of 15 (1 Reply)
Discussion started by: JamieMurry
1 Replies

7. Shell Programming and Scripting

Spliting the file dynamically

i am creating the file , when this file reaches the size 2 GB, i need one message or fire (4 Replies)
Discussion started by: kingganesh04
4 Replies

8. Shell Programming and Scripting

spliting 4gb files to 4*1 gb each

I have log file whose size is 4 GB , i would like to split it to 1 gb each ,Can any one tell me the syntax of csplit comand for that. I am using Sun0S 5.8 (3 Replies)
Discussion started by: jambesh
3 Replies

9. Shell Programming and Scripting

spliting variable value

Hi, I am reading two values from oracle to unix variable and spliting them using the read command as follows, get_details=`sqlplus -s $sld_user/$sld_password@$sld_string<<EOF whenever sqlerror exit 1 whenever oserror exit 1 set feedback off set heading off set pagesize... (0 Replies)
Discussion started by: harsh_kats
0 Replies

10. UNIX for Dummies Questions & Answers

spliting up sentences

hello, i'm looking to split up text into a list of words but can't figure it out, any help would be great. thanks steven (2 Replies)
Discussion started by: stevox
2 Replies
Login or Register to Ask a Question