Sponsored Content
Full Discussion: Splitting help required
Top Forums Shell Programming and Scripting Splitting help required Post 302935892 by George1234 on Friday 20th of February 2015 08:37:58 AM
Old 02-20-2015
The OS is HPUX version : 11

Sample Input:
Code:
01|00010103|00025.00
01|00010103|00045.00
01|00010103|00080.00
01|00010103|00067.00
01|00010103|00067.95
01|00010287|00025.00
01|00010287|00045.00
01|00010287|00080.00
01|00010287|00067.00
01|00010299|00025.00
01|00010299|00045.00
01|00010299|00080.00
01|00010299|00067.00
01|00010299|00067.95
01|00010500|00025.00
01|00010500|00067.95
01|00010724|00025.00
01|00010724|00045.00

Sample outputs:
file1:
Code:
01|00010103|00025.00
01|00010103|00045.00
01|00010103|00080.00
01|00010103|00067.00
01|00010103|00067.95

Code:
file2
01|00010287|00025.00
01|00010287|00045.00
01|00010287|00080.00
01|00010287|00067.00

file3
Code:
01|00010299|00025.00
01|00010299|00045.00
01|00010299|00080.00
01|00010299|00067.00
01|00010299|00067.95

file4
Code:
01|00010500|00025.00
01|00010500|00067.95
01|00010724|00025.00
01|00010724|00045.00

The logic will be:
1. the total number of lines should be 1000 in 1st 3 splitted file rest will go to 4th one. but if the 2nd field value present in line number 999 and 1001 is same, it will continue, unless it encounter new 2nd field.
2. The total number of file is 4.

---------- Post updated at 08:37 AM ---------- Previous update was at 01:21 AM ----------

I searched and found below code, it can be helpful. But it don't rectrict number of files to 4. Can some please do it.
Code:
awk 'BEGIN {
        FS = OFS = "|"
        fn = "F" ++fc
}
c >= 1000 && $2 != last {
        close fn
        fn = "F" ++fc
        c = 0
}
{       print > fn
        last = $2
        c++
  
}' file.txt

 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Splitting the input value

Hi, I have a Variable Char field coming whose value looks like below 562432569856 I need to extract 2 characters from it till the end and put it elsewhere say 56 24 32 56 98 56 in this case. Any input is appreciated. (2 Replies)
Discussion started by: thumsup9
2 Replies

2. UNIX for Dummies Questions & Answers

Splitting a line

I have a series of .txt files, that contain lines of text separated by the following string ==================== In some of the .txt files, the string ends with the word Document, leaving the string ==================Document. I would like to be able to split any such line and move the word... (16 Replies)
Discussion started by: spindoctor
16 Replies

3. Shell Programming and Scripting

Need help in splitting the file

Hi, I got a file which may have 100 - 500 rows with header and trailer... based on the total number of real rows ( excluding header and trailer) I want to break the file in 3 or 4 files .. Coded like this .. but giving error in the AWK in 8th line of below code. awk 'NR > 5 {print line}... (3 Replies)
Discussion started by: Vaddadi
3 Replies

4. Shell Programming and Scripting

Getting required fields from a test file in required fromat in unix

My data is something like shown below. date1 date2 aaa bbbb ccccc date3 date4 dddd eeeeeee ffffffffff ggggg hh I want the output like this date1date2 aaa eeeeee I serached in the forum but didn't find the exact matching solution. Please help. (7 Replies)
Discussion started by: rdhanek
7 Replies

5. Shell Programming and Scripting

help in splitting

Hi experts, In the lines below I am trying to copy only the words which come after "//" into an array short nloh; // Comments int age; // Age of the person Please help me in achieving this After the code, the output of the array should Comments Age of the person (6 Replies)
Discussion started by: ramakanth_burra
6 Replies

6. Shell Programming and Scripting

need help in splitting the file

hi i have file with the format as below. header and associated company details company,accno,accname,amount abc,123,checking,100 abc,234,saving,200 company,accno,accname,amount def,678,checking,100 def,222,saving,200 company,accno,accname,amount dfdf,567,checking,100... (4 Replies)
Discussion started by: dsdev_123
4 Replies

7. Shell Programming and Scripting

splitting value

Hello, i want to take a one word from my file. -- myfile.txt -- test blablabla suPHP_ConfigPath /home/performe/etc blablabla etc. bla bla. -- myfile.txt -- How can i take performe from this file ? Thank you. (7 Replies)
Discussion started by: SAYGIN
7 Replies

8. Shell Programming and Scripting

Help required in Splitting a xml file into multiple and appending it in another .xml file

HI All, I have to split a xml file into multiple xml files and append it in another .xml file. for example below is a sample xml and using shell script i have to split it into three xml files and append all the three xmls in a .xml file. Can some one help plz. eg: <?xml version="1.0"?>... (4 Replies)
Discussion started by: ganesan kulasek
4 Replies

9. Shell Programming and Scripting

Help with splitting of file

Hi, I'm beginner in UNIX I would like to split file in separate files depending on Pattern. Input file looks like:-A B C brfbeg A B C brfbeg A B C brfbeg . . n so on (7 Replies)
Discussion started by: Rohit_Mokal
7 Replies

10. Shell Programming and Scripting

Splitting a file

I have a source file where a record starts with # entry-id: followed by a number. i want to move the record in file 1 iff the second row is "dn: uid=.*,ou=perm,dc=mssb,dc=com" and the record to file 2 if contents of second row anything else # entry-id: 1 dn:... (6 Replies)
Discussion started by: r_t_1601
6 Replies
Locale::Codes::LangFam(3pm)				 Perl Programmers Reference Guide			       Locale::Codes::LangFam(3pm)

NAME
Locale::Codes::LangFam - standard codes for language extension identification SYNOPSIS
use Locale::Codes::LangFam; $lext = code2langfam('apa'); # $lext gets 'Apache languages' $code = langfam2code('Apache languages'); # $code gets 'apa' @codes = all_langfam_codes(); @names = all_langfam_names(); DESCRIPTION
The "Locale::Codes::LangFam" module provides access to standard codes used for identifying language families, such as those as defined in ISO 639-5. Most of the routines take an optional additional argument which specifies the code set to use. If not specified, the default ISO 639-5 language family codes will be used. SUPPORTED CODE SETS
There are several different code sets you can use for identifying language families. A code set may be specified using either a name, or a constant that is automatically exported by this module. For example, the two are equivalent: $lext = code2langfam('apa','alpha'); $lext = code2langfam('apa',LOCALE_LANGFAM_ALPHA); The codesets currently supported are: alpha This is the set of three-letter (lowercase) codes from ISO 639-5 such as 'apa' for Apache languages. This is the default code set. ROUTINES
code2langfam ( CODE [,CODESET] ) langfam2code ( NAME [,CODESET] ) langfam_code2code ( CODE ,CODESET ,CODESET2 ) all_langfam_codes ( [CODESET] ) all_langfam_names ( [CODESET] ) Locale::Codes::LangFam::rename_langfam ( CODE ,NEW_NAME [,CODESET] ) Locale::Codes::LangFam::add_langfam ( CODE ,NAME [,CODESET] ) Locale::Codes::LangFam::delete_langfam ( CODE [,CODESET] ) Locale::Codes::LangFam::add_langfam_alias ( NAME ,NEW_NAME ) Locale::Codes::LangFam::delete_langfam_alias ( NAME ) Locale::Codes::LangFam::rename_langfam_code ( CODE ,NEW_CODE [,CODESET] ) Locale::Codes::LangFam::add_langfam_code_alias ( CODE ,NEW_CODE [,CODESET] ) Locale::Codes::LangFam::delete_langfam_code_alias ( CODE [,CODESET] ) These routines are all documented in the Locale::Codes::API man page. SEE ALSO
Locale::Codes The Locale-Codes distribution. Locale::Codes::API The list of functions supported by this module. http://www.loc.gov/standards/iso639-5/id.php ISO 639-5 . AUTHOR
See Locale::Codes for full author history. Currently maintained by Sullivan Beck (sbeck@cpan.org). COPYRIGHT
Copyright (c) 2011-2013 Sullivan Beck This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.18.2 2013-11-04 Locale::Codes::LangFam(3pm)
All times are GMT -4. The time now is 07:54 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy