Sponsored Content
Top Forums Shell Programming and Scripting Split a content in a file with specific interval base on the delimited values using UNIX command Post 303004208 by KK230689 on Thursday 28th of September 2017 02:03:19 AM
Old 09-28-2017
Split a content in a file with specific interval base on the delimited values using UNIX command

Hi All,


we have a requirement to split a content in a text file every 5 rows and write in a new file .

conditions:

if 5th line falls between center of the statement . it should look upto after ";"


files are below format:

Code:
1	UPDATE TABLE TEST1 SET VALUE ='AFDASDFAS'
2	WHERE EMP='121'
3	;
4	UPDATE TABLE TEST1 SET VALUE ='AFDASDFAS'
5	WHERE EMP='121'
6	;
7	UPDATE TABLE TEST1 SET VALUE ='AFDASDFAS'
8	WHERE EMP='121'
9	;
10	UPDATE TABLE TEST1 SET VALUE ='AFDASDFAS'
11	WHERE EMP='121'
12	;
13	UPDATE TABLE TEST1 SET VALUE ='AFDASDFAS'
14	WHERE EMP='121'
15	;
16	UPDATE TABLE TEST1 SET VALUE ='AFDASDFAS'
17	WHERE EMP='121'

Output needed:

file 1:
Code:
1	UPDATE TABLE TEST1 SET VALUE ='AFDASDFAS'
2	WHERE EMP='121'
3	;
4	UPDATE TABLE TEST1 SET VALUE ='AFDASDFAS'
5	WHERE EMP='121'
6	;

file 2:
Code:
UPDATE TABLE TEST1 SET VALUE ='AFDASDFAS'
8	WHERE EMP='121'
9	;
10	UPDATE TABLE TEST1 SET VALUE ='AFDASDFAS'
11	WHERE EMP='121'
12	;

file 3:
Code:
UPDATE TABLE TEST1 SET VALUE ='AFDASDFAS'
14	WHERE EMP='121'
15	;
16	UPDATE TABLE TEST1 SET VALUE ='AFDASDFAS'
17	WHERE EMP='121'
18 :

Please dont print with line number, i make it as reference for your understanding.


Moderator's Comments:
Mod Comment Use code tags, thanks. Also please post such technical questions next time in the appropriate subforum, not the one to contact admins.

Last edited by KK230689; 09-28-2017 at 06:55 AM.. Reason: unix Shell scripting
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to split pipe delimited file

I have a pipe delimited input file as below. First byte of the each line indicate the record type. Then i need to split the file based on record_type = null,0,1,2,6 and create 5 files. How do i do this in a ksh script? Pls help |sl||SL|SL|SL|1996/04/03|1988/09/15|C|A|sl||||*|... (4 Replies)
Discussion started by: njgirl
4 Replies

2. Shell Programming and Scripting

Retrieving values from tab-delimited file in unix script

Hi I am trying to retrieve values from a tab-delimited file.I am using while read record value=`echo $record | cut -f12` done Where 12 is the column no i want retieve and record is one line of the file. But it is returning the full record. Plz help (4 Replies)
Discussion started by: akashtcs
4 Replies

3. UNIX for Dummies Questions & Answers

unix command to insert double quotes in a delimited file

Hi, I am looking for a unix command which inserts double quotes around all values in a delimited file. For example, Input File 153665031,abc,abc ,abc 131278839,def,def ,dec 179821481,efg,efg ,lmn ... (6 Replies)
Discussion started by: Bachu
6 Replies

4. Shell Programming and Scripting

Extract value from delimited file base on white list

I would like to use a variable to store the IDs that I would like to extract. I would like to extract a list of values of the IDs from a delimited string. Using bash here. file format would be id1=we1;id2=er2;id3=rt3;id4=yu4 The number of fields and records is not fixed. There could be... (2 Replies)
Discussion started by: milo7
2 Replies

5. Shell Programming and Scripting

how to Insert values in multiple lines(records) within a pipe delimited text file in specific cols

this is Korn shell unix. The scenario is I have a pipe delimited text file which needs to be customized. say for example,I have a pipe delimited text file with 15 columns(| delimited) and 200 rows. currently the 11th and 12th column has null values for all the records(there are other null columns... (4 Replies)
Discussion started by: vasan2815
4 Replies

6. Shell Programming and Scripting

split file content into specific folders

Hi I have a large text file and I want to split its content into multiple flies. this large file contains several blocks of codes separated by a comment line for each block. this comment line represents a directory path So, when separate these blocks each into a separate file, This output... (7 Replies)
Discussion started by: turki_00
7 Replies

7. UNIX for Dummies Questions & Answers

Quick UNIX command to display specific lines in the middle of a file from/to specific word

This could be a really dummy question. I have a log text file. What unix command to extract line from specific string to another specific string. Is it something similar to?: more +/"string" file_name Thanks (4 Replies)
Discussion started by: aku
4 Replies

8. Linux

Split a large textfile (one file) into multiple file to base on ^L

Hi, Anyone can help, I have a large textfile (one file), and I need to split into multiple file to break each file into ^L. My textfile ========== abc company abc address abc contact ^L my company my address my contact my skills ^L your company your address ========== (3 Replies)
Discussion started by: fspalero
3 Replies

9. Shell Programming and Scripting

Split Big XML file Base on tag

HI I want to split file base on tag name. I have few header and footer on file <?xml version="1.33" encing="UTF-8"?> <bulkCmConfigDataFile" <xn:SubNetwork id="ONRM_ROOT"> <xn:MeContext id="PPP04156"> ... (4 Replies)
Discussion started by: pareshkp
4 Replies

10. UNIX for Beginners Questions & Answers

awk command to split pipe delimited file

Hello, I need to split a pipe de-limited file based on the COLUMN 7 value . If the column value changes I need to split the file Source File Payment|ID|DATE|TIME|CONTROLNUMBER|NUMBER|NAME|INDICATOR 42156974|1137937|10/1/2018|104440|4232|2054391|CARE|1... (9 Replies)
Discussion started by: rosebud123
9 Replies
All times are GMT -4. The time now is 10:20 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy