Sponsored Content
Top Forums Shell Programming and Scripting splitting files based on text in the file Post 97468 by Ygor on Monday 30th of January 2006 07:45:46 PM
Old 01-30-2006
Awk is the obvious choice. For example, read infile and create outfile.1, outfile.2, etc....
Code:
awk 'BEGIN{cnt=1}(condition){cnt++}{print $0 > "outfile." cnt}' infile

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Splitting text file to several other files using sed.

I'm trying to figure out how to do this efficiently with as little execution time as possible and I'm pretty sure using sed is the best way. However I'm new to sed and all the reading and examples I've found don't seem to show a similar exercise: I have a long text file (i'll call it... (3 Replies)
Discussion started by: JeffV
3 Replies

2. Shell Programming and Scripting

Splitting text file into 2 separate files ??

Hi All, I am new to this forumn as well to the UNIX, I have basic knowledge of UNIX which I studied some years ago, now I have to do some shell scripting to load data into Oracle database using sqlldr utility, whcih I am able to do. I have a requirement where I need to do following operation. I... (10 Replies)
Discussion started by: shekharjchandra
10 Replies

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

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

5. UNIX for Dummies Questions & Answers

Splitting up a text file into multiple files by columns

Hi, I have a space delimited text file with multiple columns 102 columns. I want to break it up into 100 files labelled 1.txt through 100.txt (n.txt). Each text file will contain the first two columns and in addition the nth column (that corresponds to n.txt). The third file will contain the... (1 Reply)
Discussion started by: evelibertine
1 Replies

6. Shell Programming and Scripting

Splitting records in a text file based on delimiter

A text file has 2 fields (Data, Filename) delimited by # as below, Data,Filename Row1 -> abc#Test1.xml Row2 -> xyz#Test2.xml Row3 -> ghi#Test3.xml The content in first field has to be written into a file where filename should be considered from second field. So from... (4 Replies)
Discussion started by: jayakkannan
4 Replies

7. Shell Programming and Scripting

Sed: Splitting A large File into smaller files based on recursive Regular Expression match

I will simplify the explaination a bit, I need to parse through a 87m file - I have a single text file in the form of : <NAME>house........ SOMETEXT SOMETEXT SOMETEXT . . . . </script> MORETEXT MORETEXT . . . (6 Replies)
Discussion started by: sumguy
6 Replies

8. Shell Programming and Scripting

Rename files based on name in text file

Hello, I have a text file "file.list" with the contents below. file1 filename1 file2 filename2 file3 filename3 file1, file2 and file3 are files existing in the same directory as the text file file.list. I want to rename file1 to filename1, file2 to filename2, as show in the text... (1 Reply)
Discussion started by: james2009
1 Replies

9. UNIX for Beginners Questions & Answers

Rename files based on simple text file

Hello! New here although not completely new to Unix. I wonder how I could rename files based on the data found in a simple textfile. It goes like this: I have 4 files 1 ldfgkkfjslkdfjsldkfjsf.wav 2 nndsdflksdjf.wav 3 sdflksjdf jjsdflsdfl.wav 4 dkadsdddd.wav Textfile.txt looks like... (14 Replies)
Discussion started by: Oortone
14 Replies

10. Shell Programming and Scripting

Splitting a text file into smaller files with awk, how to create a different name for each new file

Hello, I have some large text files that look like, putrescine Mrv1583 01041713302D 6 5 0 0 0 0 999 V2000 2.0928 -0.2063 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0 5.6650 0.2063 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0 3.5217 ... (3 Replies)
Discussion started by: LMHmedchem
3 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 06:03 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy