Sponsored Content
Top Forums Shell Programming and Scripting Split a single file into multiple files based on a value. Post 302967332 by ROCK_PLSQL on Tuesday 23rd of February 2016 12:00:18 AM
Old 02-23-2016
Hi All,

Thanks a lot to all.

I forgot to mention one thing the sales_data.csv is having heading.
Code:
SCID     NAME     SCODE           CREATE_DATE
SDDCCR;  SOM   ; MD6546474777   ;05-JAN-16
ABC   ;  KIRAN ; CB789          ;04-JAN-16
ABC   ;  RAMANA; KS566767477747 ;06-JAN-16
ABC   ;  KAMESH; A33535335      ;04-JAN-16
SDDCCR;  DINESH; GD6674474747   ;08-JAN-16
SDDCCR;  SUJAN ; SA6666464664646;05-JAN-16
XYZ  ;   AMAR  ; AB123456       ;04-JAN-16
XYZ  ;   RAJ   ; CS78890        ;04-JAN-16
XYZ  ;   GANE  ; MD6546474777   ;08-JAN-16
XXX  ;   MANO  ; MD6546474777   ;04-JAN-16

I need heading for every split file as below.

sales_data04-JAN-16.csv

Code:
SCID     NAME     SCODE  
ABC   ;  KIRAN ; CB789          ;
ABC   ;  KAMESH; A33535335      ;
XYZ  ;   AMAR  ; AB123456       ;
XYZ  ;   RAJ   ; CS78890        ;
XXX  ;   MANO  ; MD6546474777   ;

sales_data05-JAN-16.csv

Code:
SCID     NAME     SCODE        
SDDCCR;  SOM   ; MD6546474777   ;
SDDCCR;  SUJAN ; SA6666464664646;

sales_data06-JAN-16.csv

Code:
SCID     NAME     SCODE    
ABC   ;  RAMANA; KS566767477747 ;

sales_data08-JAN-16.csv
Code:
SCID     NAME     SCODE     
SDDCCR;  DINESH; GD6674474747   ;
XYZ  ;   GANE  ; MD6546474777   ;

My below script is working fine apart from ganerating one more saparate file for heading
and not giving heading in all split files.
Code:
#!/bin/ksh 
file_name=sales_data.csv
awk ' NR==4 {HD = $1 OFS $2  OFS $3; next; next} {FN = DIR"/sales_data_"$4".csv"  file_out 
                 if (!(Se[FN]++)) print HD > FN
                 print  $1, $2, $3 >  FN}' FS=' *; *' OFS=";" DIR="$SAL_DIR" file_out $SAL_DIR/$file_name
if [ $? -ne 0 ]
then
  echo "report generation failed"
  fin_anormale $0
fi

Please help me.

Thanks.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

split a single sql file into multiple files

Hi,I have a single sql file containing many create table ddl's.Example: CREATE TABLE sec_afs ( rpt_per_typ_c char(1) NOT NULL, rpt_per_typ_t varchar(20) NULL, LOCK ALLPAGES go EXEC sp_primarykey 'sec_afs', rpt_per_typ_c go GRANT SELECT ON sec_afs TO developer_read_only... (5 Replies)
Discussion started by: smarter_aries
5 Replies

2. Shell Programming and Scripting

Split single file into multiple files based on the number in the column

Dear All, I would like to split a file of the following format into multiple files based on the number in the 6th column (numbers 1, 2, 3...): ATOM 1 N GLY A 1 -3.198 27.537 -5.958 1.00 0.00 N ATOM 2 CA GLY A 1 -2.199 28.399 -6.617 1.00 0.00 ... (3 Replies)
Discussion started by: tomasl
3 Replies

3. Shell Programming and Scripting

Split the single file lines into multiple files

Let's assume that I have a file name called ‘A' and it has 100 lines in it and would like to split these 100 lines into 4 files as specified bellow. INPUT: Input file name A 1 2 3 4 5 6 7 8 9 ........100 Output: 4 output files (x,y,z,w) File x should contains (Skip 4 lines)... (15 Replies)
Discussion started by: subbarao25
15 Replies

4. Shell Programming and Scripting

Split a file into multiple files based on the input pattern

I have a file with lines something like. ...... 123_start ...... ....... 123_end .... ..... 456_start ...... ..... 456_end .... ..... 789_start .... .... 789_end (6 Replies)
Discussion started by: abinash
6 Replies

5. Shell Programming and Scripting

split XML file into multiple files based on pattern

Hello, I am using awk to split a file into multiple files using command: nawk '{ if ( $1 == "<process" ) { n=split($2, arr, "\""); file=arr } print > file }' processes.xml <process name="Process1.process"> ... (3 Replies)
Discussion started by: chiru_h
3 Replies

6. Shell Programming and Scripting

Split a file into multiple files based on field value

Hi, I've one requirement. I have to split one comma delimited file into multiple files based on one of the column values. How can I achieve this Unix Here is the sample data. In this case I have split the files based on date column(c4) Input file c1,c2,c3,c4,c5... (1 Reply)
Discussion started by: manasvi24
1 Replies

7. Shell Programming and Scripting

Split single file into multiple files using pattern matching

I have one single shown below and I need to break each ST|850 & SE to separate file using unix script. Below example should create 3 files. We can use ST & SE to filter as these field names will remain same. Please advice with the unix code. ST|850 BEG|PO|1234 LIN|1|23 SE|4 ST|850... (3 Replies)
Discussion started by: prasadm
3 Replies

8. Shell Programming and Scripting

awk script to split file into multiple files based on many columns

So I have a space delimited file that I'd like to split into multiple files based on multiple column values. This is what my data looks like 1bc9A02 1 10 1000 FTDLNLVQALRQFLWSFRLPGEAQKIDRMMEAFAQRYCQCNNGVFQSTDTCYVLSFAIIMLNTSLHNPNVKDKPTVERFIAMNRGINDGGDLPEELLRNLYESIKNEPFKIPELEHHHHHH 1ku1A02 1 10... (9 Replies)
Discussion started by: viored
9 Replies

9. Shell Programming and Scripting

Split a big file into multiple files based on first four characters

I have a requirement to split a huge file to smaller text files based on first four characters which look like ABCD 1234 DFGH RREX : : : : : 0000 Each of these records are OF EQUAL bytes with a different internal layout based on the above first digit identifier.. Any help to start... (5 Replies)
Discussion started by: etldev
5 Replies

10. UNIX for Beginners Questions & Answers

Split file into multiple files based on empty lines

I am using below code to split files based on blank lines but it does not work. awk 'BEGIN{i=0}{RS="";}{x="F"++i;}{print > x;}' Your help would be highly appreciated find attachment of sample.txt file (2 Replies)
Discussion started by: imranrasheedamu
2 Replies
SOAP::WSDL::Deserializer::SOM(3pm)			User Contributed Perl Documentation			SOAP::WSDL::Deserializer::SOM(3pm)

NAME
SOAP::WSDL::Deserializer::SOM - Deserializer SOAP messages into SOM objects SYNOPSIS
use SOAP::WSDL; use SOAP::WSDL::Deserializer::SOM; use SOAP::WSDL::Factory::Deserializer; SOAP::WSDL::Factory::Deserializer->register( '1.1', __PACKAGE__ ); DESCRIPTION
Deserializer for creating SOAP::Lite's SOM object as result of a SOAP call. This package is here for two reasons: o Compatibility You don't have to change the rest of your SOAP::Lite based app when switching to SOAP::WSDL, but can just use SOAP::WSDL::Deserializer::SOM to get back the same objects as you were used to. o Completeness SOAP::Lite covers much more of the SOAP specification than SOAP::WSDL. SOAP::WSDL::Deserializer::SOM can be used for content which cannot be deserialized by SOAP::WSDL::Deserializer::SOAP11. This may be XML including mixed content, attachements and other XML data not (yet) handled by SOAP::WSDL::Deserializer::SOAP11. SOAP::WSDL::Deserializer::SOM is a subclass of SOAP::Deserializer from the SOAP::Lite package. METHODS
deserialize Deserializes a XML sting into a SOAP::SOM object. Returns a SOAP::Fault object on deserialization errors. generate_fault Dies with a SOAP::Fault object. USAGE
SOAP::WSDL::Deserializer will not autoregister itself - to use it for a particular SOAP version just use the following lines: my $soap_version = '1.1'; # or '1.2', further versions may appear. use SOAP::WSDL::Deserializer::SOM; use SOAP::WSDL::Factory::Deserializer; SOAP::WSDL::Factory::Deserializer->register( $soap_version, __PACKAGE__ ); DIFFERENCES FROM OTHER CLASSES
Differences from SOAP::Lite o No on_fault handler You cannot specify what to do when an error occurs - SOAP::WSDL will return a SOAP::Fault object on transport errors. Differences from other SOAP::WSDL::Deserializer classes o generate_fault SOAP::WSDL::Deserializer::SOM will die with a SOAP::Fault object on calls to generate_fault. This also means that a SOAP::Fault may be thrown as exception when using LICENSE AND COPYRIGHT
Copyright 2004-2007 Martin Kutter. This file is part of SOAP-WSDL. You may distribute/modify it under the same terms as perl itself. AUTHOR
Martin Kutter <martin.kutter fen-net.de> REPOSITORY INFORMATION
$Rev: 851 $ $LastChangedBy: kutterma $ $Id: SOM.pm 851 2009-05-15 22:45:18Z kutterma $ $HeadURL: https://soap-wsdl.svn.sourceforge.net/svnroot/soap-wsdl/SOAP-WSDL/trunk/lib/SOAP/WSDL/Deserializer/SOM.pm $ perl v5.10.1 2010-12-21 SOAP::WSDL::Deserializer::SOM(3pm)
All times are GMT -4. The time now is 10:09 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy