Sponsored Content
Top Forums Shell Programming and Scripting Split the single file lines into multiple files Post 302418922 by anbu23 on Wednesday 5th of May 2010 05:45:06 PM
Old 05-05-2010
What have you tried?
 

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. UNIX for Dummies Questions & Answers

Split single file into n number of files

Hi, I am new to unix. we have a requirement here to split a single file into multiples files based on the number of people available for processing. So i tried my hand at writing some code as below. #!/bin/bash var1=`wc -l $filename` var2=$var1/$splitno split -l $var2 $1 Please help me... (6 Replies)
Discussion started by: quirkguy
6 Replies

4. Shell Programming and Scripting

Awk match multiple columns in multiple lines in single file

Hi, Input 7488 7389 chr1.fa chr1.fa 3546 9887 chr5.fa chr9.fa 7387 7898 chrX.fa chr3.fa 7488 7389 chr21.fa chr3.fa 7488 7389 chr1.fa chr1.fa 3546 9887 chr9.fa chr5.fa 7898 7387 chrX.fa chr3.fa Desired Output 7488 7389 chr1.fa chr1.fa 2 3546 9887 chr5.fa chr9.fa 2... (2 Replies)
Discussion started by: jacobs.smith
2 Replies

5. 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

6. Shell Programming and Scripting

Split: File into multiple and keeping the same 3 lines from input into all output files

The following code will split the infile into multiple files. However, I need it to insert the same first 3 lines from the original input file into each splitted file. How do I modify my script below to do so: print -n "Enter file name to split? " ; read infile if then echo "Invalid file... (4 Replies)
Discussion started by: mrn6430
4 Replies

7. Shell Programming and Scripting

Single command to create multiple empty files(no trailing lines as well).

Hi, i need a single command to create multiple empty files(no trailing lines as well) and empty the files if already existing. please let me know or if this has been ansered, if some ocan share the link please, thanks > newfile.txt or :> newfile.txt do not work (4 Replies)
Discussion started by: Onkar Banerjee
4 Replies

8. UNIX for Dummies Questions & Answers

Split files into smaller ones with 1000 hierarchies in a single file.

input file: AD,00,--,---,---,---,---,---,---,--,--,--- AM,000,---,---,---,---,---,--- AR, ,---,--,---,--- AA,---,---,---,--- AT,--- AU,---,---,--- AS,---,--- AP,---,---,--- AI,--- AD,00,---,---,---, ,---,---,---,---,---,--- AM,000,---,---,--- AR,... (6 Replies)
Discussion started by: kcdg859
6 Replies

9. Shell Programming and Scripting

Split a single file into multiple files based on a value.

Hi All, I have the sales_data.csv file in the directory as below. 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... (4 Replies)
Discussion started by: ROCK_PLSQL
4 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
csplit(1)						      General Commands Manual							 csplit(1)

Name
       csplit - context split

Syntax
       csplit [ -s ] [ -k ] [ -f prefix ] file arg1 [ ...argn ]

Description
       The command reads file and separates it into n+1 sections, as defined by the arguments arg1...argn.  By default, the sections are placed in
       xx00...xxn (n may not be greater than 99).  The named file is sectioned in the following way:

       00:   From the start of file up to (but not including) the line referenced by arg1.

       01:   From the line referenced by arg1 up to the line referenced by arg2.
	     .
	     .
	     .

       n:    From the line referenced by argn to the end of file.

       If the file argument is a minus (-) then standard input is used. A minus is an ASCII octal 055.

Options
       -s		   Suppresses the printing of all character counts.  If the -s option is omitted, the command prints the character  counts
			   for each file created.

       -k		   Leaves  previously  created files intact.  If the -k option is omitted, automatically removes created files if an error
			   occurs.

       -fprefix 	   Names the created files prefix00...prefixn.	The default is xx00...xxn.

       The arguments (arg1...argn) to can be a combination of the following:

	     /rexp/[offset]	 A file is created for the section from the current line up to (but not including) the line containing the regular
				 expression  rexp.   The  current line becomes the line containing rexp.  The optional offset is plus (+) or minus
				 (-) the number of lines.  For example, /Page/-5.

	     %rexp%[offset]	 This argument is the same as /rexp/[offset], except that no file is created for the section.

	     lnno		 A file is created from the current line up to (but not including) lnno.  The current line becomes lnno.

	     {num}		 Repeat argument.  This argument may follow any of the above arguments.  If it follows a rexp argument, that argu-
				 ment  is  applied  num  more times.  If it follows lnno, the file will be split every lnno lines (num times) from
				 that point.

       Enclose all rexp type arguments that contain blanks or other characters meaningful to the Shell in the appropriate quotes.  Regular expres-
       sions should not contain embedded new-lines.  The command does not affect the original file; it is the user's responsibility to remove it.

Examples
       csplit -f cobol file /procedure division/ /par5./ /par16./
       This example creates four files, cobol00...cobol03.  After editing the files that created, they can be recombined as follows:
       cat cobol0[0-3] > file
       Note that this example overwrites the original file.

       csplit -k file  100  {99}
       This  example splits the file every 100 lines, up to 10,000 lines.  The -k option causes the created files to be retained if there are less
       than 10,000 lines; however, an error message would still be printed.

       csplit -k prog.c  '%main(%'  '/^}/+1'  {20}
       Assuming that follows the normal C coding convention of ending routines with a right brace (}) at the beginning of the line,  this  example
       creates a file containing each separate C routine (up to 21) in

Diagnostics
       The diagnostics are self explanatory except for the following:
       arg - out of range
       This message means that the given argument did not reference a line between the current position and the end of the file.

See Also
       ed(1), sh(1)

																	 csplit(1)
All times are GMT -4. The time now is 08:03 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy