Sponsored Content
Top Forums Shell Programming and Scripting Split the single file lines into multiple files Post 302418923 by pseudocoder on Wednesday 5th of May 2010 05:48:42 PM
Old 05-05-2010
Code:
sed -n '1,${p;n;n;n;}' A > x
sed -n '2,${p;n;n;n;}' A > y
sed -n '3,${p;n;n;n;}' A > z
sed -n '4,${p;n;n;n;}' A > w

 

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 SYNOPSIS
prefix] number] file arg1 [...argn] DESCRIPTION
reads file, separates it into n+1 sections as defined by the arguments arg1 ... argn, and places the results in separate files. The maxi- mum number of arguments (arg1 through argn) allowed is 99 unless the option is used to allow for more output file names. If the option is specified, the resulting filenames are through prefixNN where NN is the two-digit value of n using a leading zero if n is less than 10. If the option is not specified, the default filenames through are used. file is divided as follows: Default Prefixed Filename Filename Contents ----------------------------------------------------- xx00 prefix00 From start of file up to (but not including) the line refer- enced by arg1. xx01 prefix01 From the line referenced by arg1 up to the line referenced by arg2. . . . xxNN prefixNN From the line referenced by argn to end of file. If the file argument is standard input is used. supports the Basic Regular Expression syntax (see regexp(5)). Options recognizes the following options: Suppress printing of all character counts normally prints the character counts for each file created). Leave previously created files intact normally removes created files if an error occurs). Name created files through prefixNN (default is through The output file name suffix will use number digits instead of the default This allows creation of more than 100 output files. Arguments (arg1 through argn) to can be any combination of the following: Create a file containing the section from the current line up to (but not including) the line matching the regular expression regexp. The new current line becomes the line matching regexp. Create a file containing the section from the current line up to (but not including) the nth before or after the line matching the regular expression regexp. (e.g., The new current line becomes the line matching plus or minus n lines. equivalent to except that no file is created for the section. line_number Create a file from the current line up to (but not including) line_number. The new current line becomes line_number. Repeat argument. This argument can follow any of the above argument forms. If it follows a regexp argument, that argument is applied num more times. If it follows line_number, the file is split every line_number lines for num times from that point until end-of-file is reached or num expires. Repeats previous operand as many times as necessary to finish input. Enclose in appropriate quotes all regexp arguments containing blanks or other characters meaningful to the shell. Regular expressions must not contain embedded new-lines. does not alter or remove the original file; it is the user's responsibility to remove it when appropriate. EXTERNAL INFLUENCES
Environment Variables determines the collating sequence used in evaluating regular expressions. determines the characters matched by character class expressions in regular expressions. determines the language in which messages are displayed. If or or is not specified in the environment or is set to the empty string, the value of is used as a default for each unspecified or empty variable. If is not specified or is set to the empty string, a default of "C" (see lang(5)) is used instead of If any internationalization variable contains an invalid setting, behaves as if all internationalization variables are set to "C". See environ(5). International Code Set Support Single- and multi-byte character code sets are supported. DIAGNOSTICS
Messages are self explanatory except for: which means that the given argument did not reference a line between the current position and the end of the file. This warning also occurs if the file is exhausted before the repeat count is. EXAMPLES
Create four files, through After editing the ``split'' files, recombine them back into the original file, destroying its previous contents. Perform editing operations Split a file at every 100 lines, up to 10,000 lines (100 files). The option causes the created files to be retained if there are fewer than 10,000 lines (an error message is still printed). Assuming that follows the normal C coding convention of terminating routines with a at the beginning of the line, create a file containing each separate C routine (up to 21) in SEE ALSO
sh(1), split(1), environ(5), lang(5), regexp(5). STANDARDS CONFORMANCE
csplit(1)
All times are GMT -4. The time now is 04:21 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy