Splitting a txt file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Splitting a txt file
# 1  
Old 10-03-2006
Splitting a txt file

HI! all

I have a text file which contains 90,000 records.my requirement is to split this file in to four parts becuse according to an requirement a file should contain 25,000 records only .After splitting i need to concatenate the timestamp with the file name ,

Plese can any 1 help me

Thanks in Advance

Tausif
# 2  
Old 10-03-2006
Try...
Code:
split -l 25000 yourinputfile

Here -l is -{small letter L} and above command will make following four files, in the same directory:
Code:
xaa ---->First 25,000 Lines
xab  ---->25-50000 Lines
xac ----->50-75000 Lines
xad ----->75-90000 Lines

Regards,
Tayyab
# 3  
Old 10-03-2006
when i used Spilit command,iam getting four file not in text format but in operating system format,i nee those four outputfiles in txt fornmat
# 4  
Old 10-03-2006
What you mean by operating system format? If you identify a .txt file as text file, rename split generated files to .txt like xaa to xaa.txt. Otherwise post here the top 100 hundred lines of your input file and output of 2 files generated with following commands:
Code:
head +100 yourinputfile > tempfile
split -l 50 tempfile

Regards,
Tayyab
# 5  
Old 10-03-2006
Quote:
Originally Posted by mohdtausifsh
HI! all

I have a text file which contains 90,000 records.my requirement is to split this file in to four parts becuse according to an requirement a file should contain 25,000 records only .After splitting i need to concatenate the timestamp with the file name ,

Plese can any 1 help me

Thanks in Advance

Tausif
Altenative in Python:
Code:
all = open("file_with_records.txt").readlines()
open("file0-25000.txt","w").write( ''.join(all[0:25000] )  )
open("file25001-50000.txt","w").write( ''.join(all[25001:50000] ) )
open("file50001-75000.txt","w").write( ''.join(all[50001:75000] ) )
open("file75001-90000.txt","w").write( ''.join(all[75000:] ) )

# 6  
Old 10-04-2006
The Split comman is working correctly ,it is splitting the large files in to four different file ,but the file which have been splitted ar not in txt format but in someother format ,whe i checked in to Propertiesd of this file,i found the Type:File ,but not text format

Please can any one help me in this
# 7  
Old 10-04-2006
I can't help any more, I think you miss quite a few basic concepts, and I'm not sure how you are checking the properties of file and trying to display the contents of the file, by the way which operating system you are using and how you executed the above split command, how you checked the properties of split generated files? Don't go for file extensions, just try to view the contents of the file using cat command, don't worry split will generate an ASCII file against an ASCII file input.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

[Python] replicating "sha256 -C checksum_file.txt file.txt"

Hello everyone, Since my python knowledge is limimted, I've challenged myself to learn as much as possible to help me with my carrere. I'm currently trying to convert a shell script to python, just to give myself a task. There is one section of the script that I'm having issues converting and... (2 Replies)
Discussion started by: da1
2 Replies

2. UNIX for Dummies Questions & Answers

Split Every Line In Txt Into Separate Txt File, Named Same As The Line

Hi All Is there a way to export every line into new txt file where by the title of each txt output are same as the line ? I have this txt files containing names: Kandra Vanhooser Rhona Menefee Reynaldo Hutt Houston Rafferty Charmaine Lord Albertine Poucher Juana Maes Mitch Lobel... (2 Replies)
Discussion started by: Nexeu
2 Replies

3. Shell Programming and Scripting

Desired output.txt for reading txt file using awk?

Dear all, I have a huge txt file (DATA.txt) with the following content . From this txt file, I want the following output using some shell script. Any help is greatly appreciated. Greetings, emily DATA.txt (snippet of the huge text file) 407202849... (2 Replies)
Discussion started by: emily
2 Replies

4. Windows & DOS: Issues & Discussions

2 Questions: replace text in txt file, add text to end of txt file

so... Lets assume I have a text file. The text file contains multiple "#" symbols. I want to replace all thos "#"s with a STRING using DOS/Batch I want to add a certain TEXT to the end of each line. How can I do this WITHOUT aid of sed, grep or anything linux related ? (1 Reply)
Discussion started by: pasc
1 Replies

5. Shell Programming and Scripting

Need to append the date | abcddate.txt to the first line of my txt file

I want to add/append the info in the following format to my.txt file. 20130702|abcd20130702.txt FN|SN|DOB I tried the below script but it throws me some exceptions. <#!/bin/sh dt = date '+%y%m%d'members; echo $dt+|+members+$dt; /usr/bin/awk -f BEGIN { FS="|"; OFS="|"; } { print... (6 Replies)
Discussion started by: harik1982
6 Replies

6. Shell Programming and Scripting

splitting newfile.txt file and executing each splitted files

split -l $split_count newfile.txt for i in $split_files* do if test -s $workingdir/$split_files* then ./<$i.out> fi done ... (4 Replies)
Discussion started by: sanjay mn
4 Replies

7. Shell Programming and Scripting

awk append fileA.txt to growing file B.txt

This is appending a column. My question is fairly simple. I have a program generating data in a form like so: 1 20 2 22 3 23 4 12 5 43 For ever iteration I'm generating this data. I have the basic idea with cut -f 2 fileA.txt | paste -d >> FileB.txt ???? I want FileB.txt to grow, and... (4 Replies)
Discussion started by: theawknewbie
4 Replies

8. Shell Programming and Scripting

command to list .txt and .TXT file

Hi expersts, in my directory i have *.txt and *.TXT and *.TXT.log, *.txt.log I want list only .txt and .TXT files in one command... how to ?? //purple (1 Reply)
Discussion started by: thepurple
1 Replies

9. Shell Programming and Scripting

AWK CSV to TXT format, TXT file not in a correct column format

HI guys, I have created a script to read 1 column in a csv file and then place it in text file. However, when i checked out the text file, it is not in a column format... Example: CSV file contains name,age aa,11 bb,22 cc,33 After using awk to get first column TXT file... (1 Reply)
Discussion started by: mdap
1 Replies

10. UNIX for Dummies Questions & Answers

Binary txt file received when i use uuencode to send txt file as attachment

Hi, I have already read a lot of posts on sending attachments in unix...but none of them were of help for my problem...so here goes.. i wanna attach a text file and send to a mail id..used the following code : uuencode "$File1" "$File1" ;|mail -s "$Mail_sub" abc@abc.com it works... (2 Replies)
Discussion started by: ash22
2 Replies
Login or Register to Ask a Question