Sponsored Content
Top Forums Shell Programming and Scripting How to split file based on subtitle Post 302531884 by ygemici on Saturday 18th of June 2011 11:17:39 AM
Old 06-18-2011
i m not clearly but i try something related split..
Code:
# ./justdoit2 file 3
Showing 'numbered 'file1' text file ..
fruit
apple
watermelon
 
Showing 'numbered 'file2' text file ..
meat
pork
fish
 
Showing remaining lines that 'not saved a file' ..
beef
beef2

Code:
## justdoit split ## 
#!/bin/bash
i=0;f=0;l=$2;file=$1
c=$(echo $(sed -n '$=' $1) /3|bc)
while [ $(( c -=1 )) -gt -1 ] ; do
((i++));sed -n "$(($f+1)),$(($f+$l)) p" $file >$file${i};f=$(($f++$l));
done
while [ $(( x +=1 )) -le $i ] ; do
echo -e "Showing 'numbered '$file${x}' text file .. \n$(more $file${x})\n"
done
echo -e "Showing remaining lines that 'not saved a file' .. \n$(sed -n "$(($f+1)),$ p" $file)\n"

or try like this if you has split (files starts index 0.i.e..file0 , file2..)
Code:
# split -l3 -d -a1 file file

regards
ygemici
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Split file based on field

Hi I have a large file 2.6 million records and I am trying to split the file based on last column. I am doing awk -F"|" '{ print > $NF }' filename1 After around 1000 splits it gives me a error awk: can't open file 3332332423 input record number 1068, file filename1 source... (6 Replies)
Discussion started by: s_adu
6 Replies

2. Shell Programming and Scripting

Split the file based on date value

Hi frnds, I have flat file as . Say : output-file1.txt Output-file2.txt (1 Reply)
Discussion started by: Gopal_Engg
1 Replies

3. Shell Programming and Scripting

Split the file based on column

Hi, I have a file sample_1.txt (300k rows) which has data like below: * Also each record is around 64k bytes 11|1|abc|102553|125589|64k bytes of data 10|2|def|123452|123356|...... 13|2|geh|144351|121123|... 25|4|fgh|165250|118890|.. 14|1|abc|186149|116657|......... (6 Replies)
Discussion started by: sol_nov
6 Replies

4. Shell Programming and Scripting

Split the file based on pattern

Hi , I have huge files around 400 mb, which has clob data and have diffeent scenarios: I am trying to pass scenario number as parameter and and get required modified file based on the scenario number and criteria. Scenario 1: file name : scenario_1.txt ... (2 Replies)
Discussion started by: sol_nov
2 Replies

5. UNIX for Dummies Questions & Answers

Split file based on column

i have file1.txt asdas|csada|130310|0423|A1|canberra sdasd|sfdsf|130426|2328|A1|sydney Expected output : on eaceh third and fourth colum, split into each two characters asdas|csada|13|03|10|04|23|A1|canberra sdasd|sfdsf|13|04|26|23|28|A1|sydney (10 Replies)
Discussion started by: radius
10 Replies

6. Shell Programming and Scripting

Split file based on records

I have to split a file based on number of lines and the below command works fine: split -l 2 Inputfile -d OutputfileMy input file contains header, detail and trailor info as below: H D D D D TMy split files for the above command contains: First File: H DSecond File: ... (11 Replies)
Discussion started by: Ajay Venkatesan
11 Replies

7. Shell Programming and Scripting

How to Split File based on String?

hi , The scenario is like this, i have a large text files (max 5MB , about 5000 file per day ), Inside almost each line of this file there is a tag 3100.2.22.1 (represent Call_Type) , i need to generate many filess , each one with distinct (3100.2.22.1 Call_Type ) , and one more file to... (3 Replies)
Discussion started by: OTNA
3 Replies

8. Shell Programming and Scripting

Split File based on different conditions

I need to split the file Conditions: Ignore any record that either starts with 1 or 9 Split the file at position 404 , if position 404 is abc or def then write all the records in a file > File 1 , the remaining records should go in to a file > File 2 Further I want to split the... (7 Replies)
Discussion started by: protech
7 Replies

9. UNIX for Advanced & Expert Users

Split one file to many based on pattern

Hello All, I have records in a file in a pattern A,B,B,B,B,K,A,B,B,K Is there any command or simple logic I can pull out records into multiple files based on A record? I want output as File1: A,B,B,B,B,K File2: A,B,B,K (9 Replies)
Discussion started by: deal1dealer
9 Replies

10. Shell Programming and Scripting

Split the File based on Size

I have a file that is about 7 GB in size. The requirement is I should split the file equally in such a way that the size of the split files is less than 2Gb. If the file is less than 2gb, than nothing needs to be done. ( need to done using shell script) Thanks, (4 Replies)
Discussion started by: rudoraj
4 Replies
LIMITITERATOR(3)							 1							  LIMITITERATOR(3)

The LimitIterator class

INTRODUCTION
The LimitIterator class allows iteration over a limited subset of items in an Iterator. CLASS SYNOPSIS
LimitIterator LimitIteratorextends IteratorIteratorOuterIterator Methods o public LimitIterator::__construct (Iterator $iterator, [int $offset], [int $count = -1]) o public mixed LimitIterator::current (void ) o public Iterator LimitIterator::getInnerIterator (void ) o public int LimitIterator::getPosition (void ) o public mixed LimitIterator::key (void ) o public void LimitIterator::next (void ) o public void LimitIterator::rewind (void ) o public int LimitIterator::seek (int $position) o public bool LimitIterator::valid (void ) EXAMPLES
Example #1 LimitIterator usage example <?php // Create an iterator to be limited $fruits = new ArrayIterator(array( 'apple', 'banana', 'cherry', 'damson', 'elderberry' )); // Loop over first three fruits only foreach (new LimitIterator($fruits, 0, 3) as $fruit) { var_dump($fruit); } echo " "; // Loop from third fruit until the end // Note: offset starts from zero for apple foreach (new LimitIterator($fruits, 2) as $fruit) { var_dump($fruit); } ?> The above example will output: string(5) "apple" string(6) "banana" string(6) "cherry" string(6) "cherry" string(6) "damson" string(10) "elderberry" PHP Documentation Group LIMITITERATOR(3)
All times are GMT -4. The time now is 04:10 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy