[ask]break line number into several parts


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [ask]break line number into several parts
# 1  
Old 06-24-2011
[ask]break line number into several parts

hlow all,
i have file with wc -l file.txt is 3412112 line number
so I want to break these files into several parts with assumsi line
1-1000000 will be create part1.txt and
1000001-2000000 will create part2.txt and
2000001-3000000 will create part3.txt and
3000001-3412112 will create part4.txt and
this will be continue until all line number 3412112 has finish to create

in my mine i using head and tail but i dont know must todoSmilie ..any have idea for scripting this ...

thx before
# 2  
Old 06-24-2011
There's a utility for this called split.
Code:
split -d -l 1000000 filename.txt part

# 3  
Old 06-24-2011
If you have split:
Code:
split -l 1000000 file.txt

# 4  
Old 06-25-2011
Question

ow thx for help me...

---------- Post updated 06-25-11 at 12:04 AM ---------- Previous update was 06-24-11 at 10:47 AM ----------

Quote:
Originally Posted by yazu
If you have split:
Code:
split -l 1000000 file.txt

dear all,
i using split and they create part01 part02 part03 ..
in line part01 they create 1-1000000 line number but
i cek in part02 the line number using 1-1000000 too ,same case with part03

i just want if part01 create 1-1000000 line number so part to in line number create 1000001-2000000 line number in file so they synchron line number

i want to create script like this
if search the line number in range 1-1000000 so engine will be using part01 and extract result in file.txt
and if search line number in 1000001-2000000 so engine will be using part02 and extract result in file.txt
same with part03

any idea for this...???
# 5  
Old 06-25-2011
split should work for your needs. If not try this perl script:
Code:
#!/usr/bin/env perl

# Usage: THIS_SCRIPT FILENAME

use warnings;
use strict;

# change for your needs
my $LINES=1000_000;
my $PREFIX='part';

my $cur=1;
my $out=$PREFIX . $cur;
open my $fh,'>', $out or die "$!";

while (<>) {
    if ( !($.%$LINES) ) {
		close $fh;
        $out = $PREFIX . ++$cur;
        open $fh, '>', $out or die "$!";
    }
    print $fh $_;
}

close $fh;

# 6  
Old 06-25-2011
Code:
awk 'NR%1000000==1{fn="part" ++c ".txt"}{print > fn}' file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract parts of the line

I have a long list of lines in a txt file which i'm only interested to extract the list of domains like the colored ones. domain.com domain.com/page codes $.09 domain.org domain.org/page2/ codes $0.10 domain.net domain.net/page03 codes $0.05 domain.info ... (3 Replies)
Discussion started by: garfish
3 Replies

2. Shell Programming and Scripting

Split line in 4 parts

Hi Guys, I have file A.txt 1 2 3 4 5 6 7 8 9 10 11 Want Output :- 1 2 3 (3 Replies)
Discussion started by: pareshkp
3 Replies

3. Shell Programming and Scripting

Break up file into n number of subsets and run in parallel

Hi Guys, I want to break down one of my input files into say 25 parts , run the same script in parallel and then merge the output into a single script. I have access to computing resources that can deal with 25 files, if I just run the original file the total time is about 15 days every time.... (6 Replies)
Discussion started by: gina.lizar
6 Replies

4. Shell Programming and Scripting

Incrementing parts of ten digits number by parts

I have number in file which contains date and serial number: 2013101000. The last two digits are serial number (00). So maximum of serial number is 100. After reaching 100 it becomes 00 with incrementing 10 which is day with max 31. after reaching 31 it becomes 00 and increments 10... (31 Replies)
Discussion started by: Natalie
31 Replies

5. Shell Programming and Scripting

Add line break for each line in a file

I cannot seem to get this to work.. I have a file which has about 100 lines, and there is no end of line (line break \n) at the end of each line, and this is causing problem when i paste them into an application. the file looks like this this is a test that is a test balblblablblhblbha... (1 Reply)
Discussion started by: fedora
1 Replies

6. Shell Programming and Scripting

BASH: Break line, read, break again, read again...

...when the lines use both a colon and commas to separate the parts you want read as information. The first version of this script used cut and other non-Bash-builtins, frequently, which made it nice and zippy with little more than average processor load in GNOME Terminal but, predictably, slow... (2 Replies)
Discussion started by: SilversleevesX
2 Replies

7. UNIX for Dummies Questions & Answers

How to read contents of a file from a given line number upto line number again specified by user

Hello Everyone. I am trying to display contains of a file from a specific line to a specific line(let say, from line number 3 to line number 5). For this I got the shell script as shown below: if ; then if ; then tail +$1 $3 | head -n $2 else ... (5 Replies)
Discussion started by: grc
5 Replies

8. Shell Programming and Scripting

How can i break a text file into parts that occur between a specific pattern

How can i break a text file into parts that occur between a specific pattern? I have text file having various xml many tags like which starts with the tag "<?xml version="1.0" encoding="utf-8"?>" . I have to break the whole file into several xmls by looking for the above pattern. All the... (9 Replies)
Discussion started by: abhinav192
9 Replies

9. Shell Programming and Scripting

deleting certain parts of a line in perl

I have a filr data.txt. Its contents are Available labels (* indicates activated, I indicates installed, R idicates running): abc-3.0.3 def-3.0.4 xyz-3.1.2-1.0 I want to delete " Available labels (* indicates activated, I indicates installed, R idicates running):" and... (3 Replies)
Discussion started by: lassimanji
3 Replies

10. UNIX for Dummies Questions & Answers

removing parts of a line with SED

hi, i'm trying to erase all the characters after, and including, the first test test Output: test1 test2 test3 this is what I tried, but didn't work sed "s/*//" file > testfilename any suggestions? thanks, gammmaman (2 Replies)
Discussion started by: gammaman
2 Replies
Login or Register to Ask a Question