Sponsored Content
Top Forums Shell Programming and Scripting Conditional File Splitting in Unix Post 302631003 by Rizzu155 on Thursday 26th of April 2012 03:21:41 PM
Old 04-26-2012
Conditional File Splitting in Unix

Hello Guys,

I am new to Unix and i got one requirement where I need to split my file into maximum 5 files on below conditions, if they are splitted into less than 5 then also we are fine.

Columns D value should appear in a single file only and shouldn't continue in other files.


Original file is ordered by Coulmn D (so values will appears as A,B,D,C so on)

Source data

Code:
A|B|C|D|E….
1123|1|20120426|A|A1…
1123|1|20120426|A|A2…
1123|1|20120426|B|B1…
1123|1|20120426|B|B2…
1123|1|20120426|B|B3…
1123|1|20120426|B|B4…
1123|1|20120426|B|B4…
1123|1|20120426|B|B5…
1123|1|20120426|B|B6…
1123|1|20120426|B|B7…
1123|1|20120426|B|B8…
1123|1|20120426|B|B9…
1123|1|20120426|B|B10…
1123|1|20120426|C|C1…
1123|1|20120426|C|C1…
1123|1|20120426|C|C3…
1123|1|20120426|C|C4…
1123|1|20120426|C|C5…
1123|1|20120426|D|D1…
1123|1|20120426|D|D2…

desired output

file No 1

Code:
1123|1|20120426|A|A1…
1123|1|20120426|A|A2…
1123|1|20120426|B|B1…
1123|1|20120426|B|B2…
1123|1|20120426|B|B3…
1123|1|20120426|B|B4…
1123|1|20120426|B|B4…
1123|1|20120426|B|B5…
1123|1|20120426|B|B6…
1123|1|20120426|B|B7…
1123|1|20120426|B|B8…
1123|1|20120426|B|B9…
1123|1|20120426|B|B10…


file No 2

Code:
1123|1|20120426|C|C1…
1123|1|20120426|C|C2…
1123|1|20120426|C|C3…
1123|1|20120426|C|C4…
1123|1|20120426|C|C5…
1123|1|20120426|D|D1…
1123|1|20120426|D|D2…


Last edited by Scrutinizer; 04-26-2012 at 05:03 PM.. Reason: code tags
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

splitting a string in unix

i need to split a line using a delimiter, and store it into a array :( (2 Replies)
Discussion started by: lmadhuri
2 Replies

2. Shell Programming and Scripting

splitting a pipe delimited file in unix

Could one of you shad some light on this: I need to split the file by determining the record count and than splitting it up into 4 files. Please note, this is not a fixed record length but rather a "|" delimited file. I am not sure as how to handle reminder/offset for the 4th file. For... (4 Replies)
Discussion started by: ddedic
4 Replies

3. Programming

Conditional Compilation based on Environmental Variable in Unix

I want to be able to access an environment variable to control how a program is compiled. So: export MY_VERSN=9 Then ideally, within my C++ code, I would have #if MY_VERSN = 9 iret = FRED9() #else iret = FRED() #endif The way I thought I could do it is that in the script that... (2 Replies)
Discussion started by: BrighterLater
2 Replies

4. Shell Programming and Scripting

unix script for conditional execution

Below is my shell script. I am trying to execute two different BTEQ scripts depending on the day of the week. So on a saturday I will execute a certain BTEQ script and on other weekdays I will run the other script. #!/bin/ksh dt=`date +"%a"` if then bteq > final_output <<- EOF .run... (3 Replies)
Discussion started by: Mihirjani
3 Replies

5. Shell Programming and Scripting

Conditional Splitting.

hi, I have file with some data delimited by #. For e.g. : RHMS0001#1#ABCD RHMS0002#1#ABCD RHMS0003#1#ABCD RHMS0004#1#ABCD RHMS0005#1#ABCD RHMS0006#1#ABCD RHMS0007#1#ABCD RHMS0001#2#ABCD RHMS0002#2#ABCD RHMS0001#3#ABCD RHMS0004#3#ABCD RHMS0006#3#ABCD (7 Replies)
Discussion started by: pparthiv
7 Replies

6. Shell Programming and Scripting

File splitting and grouping using unix script

Hello All, I have a small problem with file group/splitting and I am trying to get the best way to perform this in unix. I am trying with awk but need some suggestion what would be the best and fastest way to-do it. Here is the problem. I have a fixed length file with filled with product... (4 Replies)
Discussion started by: nandhan11891
4 Replies

7. Shell Programming and Scripting

Splitting large file into multiple files in unix based on pattern

I need to write a shell script for below scenario My input file has data in format: qwerty0101TWE 12345 01022005 01022005 datainala alanfernanded 26 qwerty0101mXZ 12349 01022005 06022008 datainalb johngalilo 28 qwerty0101TWE 12342 01022005 07022009 datainalc hitalbert 43 qwerty0101CFG 12345... (19 Replies)
Discussion started by: jimmy12
19 Replies

8. Shell Programming and Scripting

Help me pls : splitting single file in unix into different files based on data

I have a file in unix with sample data as follows : -------------------------------------------------------------- -------------------------------------------------------------- {30001002|XXparameter|Layout|$ I want this file to be splitted into different files and corresponding to the sample... (54 Replies)
Discussion started by: Ravindra Swan
54 Replies

9. Shell Programming and Scripting

Conditional splitting in more file

Dear All, I was wondering in how split one file in multiple file in a conditional way. Briefly, I have a file like this: >Id1 textA >Id2 textBand my outputs file (2 in this case) shoul be: Id1 >Id1 textAId2 >Id2 textBhope you may help me. Best G (5 Replies)
Discussion started by: giuliangiuseppe
5 Replies

10. UNIX for Beginners Questions & Answers

UNIX - 2 tab delimited files, conditional column extraction

Please know that I am very new to unix and trying to learn 'on the job'. I'm only manipulating large tab-delimited files (millions of rows), but I'm stuck and don't know how to proceed with the following. Hoping for some friendly advice :) I have 2 tab-delimited files - with differing column &... (10 Replies)
Discussion started by: GTed
10 Replies
ipnodes(4)							   File Formats 							ipnodes(4)

NAME
ipnodes - local database associating names of nodes with IP addresses SYNOPSIS
/etc/inet/ipnodes DESCRIPTION
The ipnodes file is a local database that associates the names of nodes with their Internet Protocol (IP) addresses. IP addresses can be either an IPv4 or an IPv6 address. The ipnodes file can be used in conjunction with, or instead of, other ipnodes databases, including the Domain Name System (DNS), the NIS ipnodes map, and the NIS+ ipnodes table. Programs use library interfaces to access information in the ipnodes file. The ipnodes file has one entry for each IP address of each node. If a node has more than one IP address, it will have one entry for each, on consecutive lines. The format of each line is: IP-address official-node-name nicknames... Items are separated by any number of <SPACE> and/or <TAB> characters. The first item on a line is the node's IP address. The second entry is the node's official name. Subsequent entries on the same line are alternative names for the same machine, or "nicknames." Nicknames are optional. For a node with more than one IP address, consecutive entries for these addresses may contain the same or differing nicknames. Different nicknames are useful for assigning distinct names to different addresses. A call to getipnodebyname(3SOCKET) returns a hostent structure containing the union of all addresses and nicknames from each line contain- ing a matching official name or nickname. A `#' indicates the beginning of a comment; characters up to the end of the line are not interpreted by routines that search the file. Network addresses are written in one of two ways: o The conventional "decimal dot" notation and interpreted using the inet_addr routine from the Internet address manipulation library, inet(3SOCKET). o The IP Version 6 protocol [IPV6], defined in RFC 1884 and interpreted using the inet_pton() routine from the Internet address manipu- lation library. See inet(3SOCKET). These interfaces supports node names as defined in Internet RFC 952 which states: A "name" (Net, Host, Gateway, or Domain name) is a text string up to 24 characters drawn from the alphabet (A-Z), digits (0-9), minus sign (-), and period (.). Note that periods are only allowed when they serve to delimit components of "domain style names". (See RFC 921, "Domain Name System Implementation Schedule," for background). No blank or space characters are permitted as part of a name. No distinction is made between upper and lower case. The first character must be an alpha character. The last character must not be a minus sign or period. Although the interface accepts node names longer than 24 characters for the node portion (exclusive of the domain component), choosing names for nodes that adhere to the 24 character restriction will insure maximum interoperability on the Internet. A node which serves as a GATEWAY should have "-GATEWAY" or "-GW" as part of its name. Nodes which do not serve as Internet gateways should not use "-GATEWAY" and "-GW" as part of their names. A node that is a TAC should have "-TAC" as the last part of its node name, if it is a DoD node. Single character names or nicknames are not allowed. RFC 952 has been modified by RFC 1123 to relax the restriction on the first character being a digit. EXAMPLES
Example 1: A Typical Line from the ipnodes File The following is a typical line from the ipnodes file: 2001:0db8:3c4d:55:a00:20ff:fe8e:f3ad myhost # John Smith SEE ALSO
getipnodebyname(3SOCKET), inet(3SOCKET), nsswitch.conf(4), resolv.conf(4), hosts(4) Braden, B., editor, RFC 1123, Requirements for Internet Hosts - Application and Support, Network Working Group, October, 1989. Harrenstien, K., Stahl, M., and Feinler, E., RFC 952, DOD INTERNET HOST TABLE SPECIFICATION, Network Working Group, October 1985. Hinden, R., and Deering, S., editors, RFC 1884, IP Version 6 Addressing Architecture, Network Working Group, December, 1995. Postel, Jon, RFC 921, Domain Name System Implementation Schedule -- Revised, Network Working Group, October 1984. NOTES
IPv4 addresses can be defined in the ipnodes file or in the hosts file. See hosts(4). The ipnodes file will be searched for IPv4 addresses when using the getipnodebyname(3SOCKET) API. If no matching IPv4 addresses are found in the ipnodes file, then the hosts file will be searched. To prevent delays in name resolution and to keep /etc/inet/ipnodes and /etc/inet/hosts synchronized, IPv4 addresses defined in the hosts file should be copied to the ipnodes file. SunOS 5.10 15 Dec 2004 ipnodes(4)
All times are GMT -4. The time now is 07:16 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy