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
PAPS(1) 						      General Commands Manual							   PAPS(1)

NAME
paps - UTF-8 to PostScript converter using Pango SYNOPSIS
paps [options] files... DESCRIPTION
paps reads a UTF-8 encoded file and generates a PostScript language rendering of the file. The rendering is done by creating outline curves through the pango ft2 backend. OPTIONS
These programs follow the usual GNU command line syntax, with long options starting with two dashes (`-'). A summary of options is included below. --landscape Landscape output. Default is portrait. --columns=cl Number of columns output. Default is 1. Please notice this option isn't related to the terminal length as in a "80 culums terminal". --font=desc Set the font description. Default is Monospace 12. --rtl Do right to left (RTL) layout. --paper ps Choose paper size. Known paper sizes are legal, letter and A4. Default is A4. Postscript points Each postscript point equals to 1/72 of an inch. 36 points are 1/2 of an inch. --bottom-margin=bm Set bottom margin. Default is 36 postscript points. --top-margin=tm Set top margin. Default is 36 postscript points. --left-margin=lm Set left margin. Default is 36 postscript points. --right-margin=rm Set right margin. Default is 36 postscript points. --gutter-width=gw Set gutter width. Default is 40 postscript points. --help Show summary of options. --header Draw page header for each page. --markup Interpret the text as pango markup. --lpi Set the lines per inch. This determines the line spacing. --cpi Set the characters per inch. This is an alternative method of specifying the font size. --stretch-chars Indicates that characters should be stretched in the y-direction to fill up their vertical space. This is similar to the texttops behaviour. AUTHOR
paps was written by Dov Grobgeld <dov.grobgeld@gmail.com>. This manual page was written by Lior Kaplan <kaplan@debian.org>, for the Debian project (but may be used by others). April 17, 2006 PAPS(1)
All times are GMT -4. The time now is 05:33 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy