Copy data to new file based on input pattern


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Copy data to new file based on input pattern
# 8  
Old 10-21-2017
Dear Don,

Thnx for your effort. The command provided by you worked perfectly fine and I was able to select all the records with Add headers and subsequent result.Smilie

Dear Ravinder,

Thnx for your effort.Smilie

Below is my requirement and output.
Input file:
Code:
ORDER|Header|Add|32|32|1616
ORDER|Details1.........
ORDER|Details2.........
ORDER|Details3.........
ORDER|Details4.........
ORDER|T|32|32|1616
ORDER|Header|Modify|32|32|1617
ORDER|Details1.........
ORDER|Details2.........
ORDER|Details3.........
ORDER|Details4.........
ORDER|T|32|32|1617
ORDER|Header|Add|32|32|1618
ORDER|Details1.........
ORDER|Details2.........
ORDER|Details3.........
ORDER|Details4.........
ORDER|T|32|32|1618
ORDER|Header|Add|32|32|1619
ORDER|Details1.........
ORDER|Details2.........
ORDER|Details3.........
ORDER|Details4.........
ORDER|T|32|32|1619

Output:
Code:
ORDER|Header|Add|32|32|1616
ORDER|Details1.........
ORDER|Details2.........
ORDER|Details3.........
ORDER|Details4.........
ORDER|T|32|32|1616
ORDER|Header|Add|32|32|1618
ORDER|Details1.........
ORDER|Details2.........
ORDER|Details3.........
ORDER|Details4.........
ORDER|T|32|32|1618
ORDER|Header|Add|32|32|1619
ORDER|Details1.........
ORDER|Details2.........
ORDER|Details3.........
ORDER|Details4.........
ORDER|T|32|32|1619

Regards.
Gaurav
# 9  
Old 10-23-2017
Dear Don,

I was going through my output and found out that the lines having Header with M (modify) lines were also included and were converted to A (Add).

But I want the lines with Headers M (modify) to be ignored (skipped).

PFB sample.

Input
Code:
ORDER|Header|Add|32|32|1616
ORDER|Details1.........
ORDER|Details2.........
ORDER|Details3.........
ORDER|Details4.........
ORDER|T|32|32|1616
ORDER|Header|Modify|32|32|1617
ORDER|Details1.........
ORDER|Details2.........
ORDER|Details3.........
ORDER|Details4.........
ORDER|T|32|32|1617

Required Output
Code:
ORDER|Header|Add|32|32|1616
ORDER|Details1.........
ORDER|Details2.........
ORDER|Details3.........
ORDER|Details4.........
ORDER|T|32|32|1616

As of now using the code you have provided, I got the output as follows.

Code:
ORDER|Header|Add|32|32|1616
ORDER|Details1.........
ORDER|Details2.........
ORDER|Details3.........
ORDER|Details4.........
ORDER|T|32|32|1616
ORDER|Header|Add|32|32|1617
ORDER|Details1.........
ORDER|Details2.........
ORDER|Details3.........
ORDER|Details4.........
ORDER|T|32|32|1617

Note:- The Modify is getting changed to Add, whereas I need to ignore the same.

Regards.
Gaurav
# 10  
Old 10-23-2017
Quote:
Originally Posted by grvk101
Dear Don,

I was going through my output and found out that the lines having Header with M (modify) lines were also included and were converted to A (Add).

But I want the lines with Headers M (modify) to be ignored (skipped).

PFB sample.

Input
Code:
ORDER|Header|Add|32|32|1616
ORDER|Details1.........
ORDER|Details2.........
ORDER|Details3.........
ORDER|Details4.........
ORDER|T|32|32|1616
ORDER|Header|Modify|32|32|1617
ORDER|Details1.........
ORDER|Details2.........
ORDER|Details3.........
ORDER|Details4.........
ORDER|T|32|32|1617

Required Output
Code:
ORDER|Header|Add|32|32|1616
ORDER|Details1.........
ORDER|Details2.........
ORDER|Details3.........
ORDER|Details4.........
ORDER|T|32|32|1616

As of now using the code you have provided, I got the output as follows.

Code:
ORDER|Header|Add|32|32|1616
ORDER|Details1.........
ORDER|Details2.........
ORDER|Details3.........
ORDER|Details4.........
ORDER|T|32|32|1616
ORDER|Header|Add|32|32|1617
ORDER|Details1.........
ORDER|Details2.........
ORDER|Details3.........
ORDER|Details4.........
ORDER|T|32|32|1617

Note:- The Modify is getting changed to Add, whereas I need to ignore the same.

Regards.
Gaurav
This is an interesting story, but there is absolutely nothing in any of the four code suggestions I supplied in post #7 in this thread that could change the string Modify to the string Add.

If a transaction termination line does not start with the exact sequence:
Code:
ORDER|T|

and a modify transaction follows it, that modify transaction might also be copied to the output but the Modify would not be changed to Add.

Please show us a sample input file that exhibits the behavior you have described above (including the exact line before the start of the modify transaction that is changed to an add transaction. And, tell us which of the four suggestions I provided exhibits the behavior you're seeing with that input.
# 11  
Old 10-23-2017
Dear Don,

Found out where the issue was. Thnx for your prompt.
There was duplicate data in 2 different file for the same number with Header as Add as well as Modify, so modify from 1 file was ignored and Add from other file was added.
Sry for the inconvenience caused.

Regards.
Gaurav
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

In PErl script: need to read the data one file and generate multiple files based on the data

We have the data looks like below in a log file. I want to generat files based on the string between two hash(#) symbol like below Source: #ext1#test1.tale2 drop #ext1#test11.tale21 drop #ext1#test123.tale21 drop #ext2#test1.tale21 drop #ext2#test12.tale21 drop #ext3#test11.tale21 drop... (5 Replies)
Discussion started by: Sanjeev G
5 Replies

2. Shell Programming and Scripting

Insert data based on pattern

if it is finding some data based on pattern 'test' then insert else if has no data based on the pattern 'test' then exit successfully cat file | grep test > file2 (3 Replies)
Discussion started by: jagu
3 Replies

3. Shell Programming and Scripting

Splitting textfile based on pattern and name new file after pattern

Hi there, I am pretty new to those things, so I couldn't figure out how to solve this, and if it is actually that easy. just found that awk could help:(. so i have a textfile with strings and numbers (originally copy pasted from word, therefore some empty cells) in the following structure: SC... (9 Replies)
Discussion started by: luja
9 Replies

4. Shell Programming and Scripting

Generate tabular data based on a column value from an existing data file

Hi, I have a data file with : 01/28/2012,1,1,98995 01/28/2012,1,2,7195 01/29/2012,1,1,98995 01/29/2012,1,2,7195 01/30/2012,1,1,98896 01/30/2012,1,2,7083 01/31/2012,1,1,98896 01/31/2012,1,2,7083 02/01/2012,1,1,98896 02/01/2012,1,2,7083 02/02/2012,1,1,98899 02/02/2012,1,2,7083 I... (1 Reply)
Discussion started by: himanish
1 Replies

5. Shell Programming and Scripting

how to get data from hex file using SED or AWK based on pattern sign

I have a binary (hex) file I need to parse to get some data which are encoded this way: .* b4 . . . 01 12 .* af .* 83 L1 x1 x2 xL 84 L2 y1 y2 yL By another words there is a stream of hexadecimal bytes (in my example separated by space for better readability). I need to get value stored in... (3 Replies)
Discussion started by: sameucho
3 Replies

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

7. Shell Programming and Scripting

Merge two file data together based on specific pattern match

My input: File_1: 2000_t g1110.b1 abb.1 2001_t g1111.b1 abb.2 abb.2 g1112.b1 abb.3 2002_t . . File_2: 2000_t Ali england 135 abb.1 Zoe british 150 2001_t Ali england 305 g1111.b1 Lucy russia 126 (6 Replies)
Discussion started by: patrick87
6 Replies

8. Shell Programming and Scripting

Copy input file based on condition

Hi, I am new to unix shell programming. I want to write a shell script for a functionality existing in mainframe system. I have one file as below as input 123456 &__987 &12yuq abcdef _ referes to blank condition:whenever the input file is having &__ ,it should be replaced... (4 Replies)
Discussion started by: charan0703
4 Replies

9. Shell Programming and Scripting

Need script to take input from file, match on it in file 2 and input data

All, I am trying to figure out a script to run in windows that will allow me to match on First column in file1 to 8th Column in File2 then Insert file1 column2 to file2 column4 then create a new file. File1: 12345 Sam 12346 Bob 12347 Bill File2:... (1 Reply)
Discussion started by: darkoth
1 Replies

10. Shell Programming and Scripting

Truncating FILE data BASED ON A PATTERN

HI I HAVE A PROBLEM,MY SOURCE FILE IS OF PATTERN S1,E-Certified,29,29,2.7,Certified,4,3,2.7,,0,0,0 S2,Certified,4,3,2.7,,0,0,0,,0 S3,E-Certified,29,29,2.7,,0,0,0 S4,,0,0,0,,0,0,0,,0,0,0,,0,0,0 AND THE EXPECTED OUTPUT IS S1,E-Certified,29,29,2.7 S1,Certified,4,3,2.7... (1 Reply)
Discussion started by: pkumar3
1 Replies
Login or Register to Ask a Question