Sponsored Content
Top Forums Shell Programming and Scripting How to split file based on subtitle Post 302531874 by sk1418 on Saturday 18th of June 2011 10:35:07 AM
Old 06-18-2011
I think the point here is not unix-skills.
In your "original file", the content must be "well sorted". e.g.
Code:
fruit
fruit1
fruit2
...
fruitn
meat
meat1
meat2
...
meatn
vegetable
vegetable1
vegetable2
...
vegetablen
...

you need to give a keyword/category list, it could be a file, that defines the different categories by name("fruit", "meat", "vegetable")

then awk can split your original file as your requirement easily.
 

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
ARRAY_WALK(3)								 1							     ARRAY_WALK(3)

array_walk - Apply a user supplied function to every member of an array

SYNOPSIS
bool array_walk NULL (array &$array, callable $callback, [mixed $userdata]) DESCRIPTION
Applies the user-defined $callback function to each element of the $array array. array_walk(3) is not affected by the internal array pointer of $array. array_walk(3) will walk through the entire array regardless of pointer position. PARAMETERS
o $array - The input array. o $callback - Typically, $callback takes on two parameters. The $array parameter's value being the first, and the key/index second. Note If $callback needs to be working with the actual values of the array, specify the first parameter of $callback as a refer- ence. Then, any changes made to those elements will be made in the original array itself. Note Many internal functions (for example strtolower(3)) will throw a warning if more than the expected number of argument are passed in and are not usable directly as a $callback. Only the values of the $array may potentially be changed; its structure cannot be altered, i.e., the programmer cannot add, unset or reorder elements. If the callback does not respect this requirement, the behavior of this function is undefined, and unpre- dictable. o $userdata - If the optional $userdata parameter is supplied, it will be passed as the third parameter to the $callback. RETURN VALUES
Returns TRUE on success or FALSE on failure. ERRORS
/EXCEPTIONS If function $callback requires more parameters than given to it, an error of level E_WARNING will be generated each time array_walk(3) calls $callback. EXAMPLES
Example #1 array_walk(3) example <?php $fruits = array("d" => "lemon", "a" => "orange", "b" => "banana", "c" => "apple"); function test_alter(&$item1, $key, $prefix) { $item1 = "$prefix: $item1"; } function test_print($item2, $key) { echo "$key. $item2<br /> "; } echo "Before ...: "; array_walk($fruits, 'test_print'); array_walk($fruits, 'test_alter', 'fruit'); echo "... and after: "; array_walk($fruits, 'test_print'); ?> The above example will output: Before ...: d. lemon a. orange b. banana c. apple d. fruit: lemon a. fruit: orange b. fruit: banana c. fruit: apple SEE ALSO
array_walk_recursive(3), iterator_apply(3), list(3), each(3), call_user_func_array(3), array_map(3), information about the callback type, foreach. PHP Documentation Group ARRAY_WALK(3)
All times are GMT -4. The time now is 11:28 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy