Copy down based on condition


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Copy down based on condition
# 1  
Old 03-27-2015
Wrench Copy down based on condition

Hello:

I need to copy down some data from the previous record in to the next record based on the below conditions

If position 41- 59 of the current record is same as the previous record and the value of position 62 is not equal to 1 then

copy the previous records value for positions 144-184 (only if the current records value is empty)

copy the previous records value for positions 184-220 (only if the current records value is empty)

copy the previous records value for positions 224-244 (only if the current records value is empty)

copy the previous records value for positions 244-246 (only if the current records value is empty)

copy the previous records value for positions 246-251 (only if the current records value is empty)

Code:
Input:

xxxx     xxxx24        68xxx          001234564              2RICHAR                   JANI                                           123456789001 HILLSIDE TERRACE                                                            HXXXXXXXXXXXX       XX77964      USA
xxxx     xxxx14        47xxx          009999996              1PALMER                   SMITH                                          9876543210009 MUNDALE WAY WEST                                                           MEXXXXX             XX38135      USA
xxxx     xxxx14        47xxx          009999996              2PALMER                   REBECCA                                        987654321                                                                                                                 USA
xxxx     xxxx14        47xxx          009999996              3SAL                      MIS                                            987654321                                                                                                                 USA
xxxx     xxxx14        47xxx          009999996              3PALMER                   JAMES                                          9876543210009 MUNDALE WAY WEST                                                           MXXXXXX             XX38135      USA


Desired Output :

xxxx     xxxx24        68xxx          001234564              2RICHAR                   JANI                                           123456789001 HILLSIDE TERRACE                                                            HXXXXXXXXXXXX       XX77964      USA
xxxx     xxxx14        47xxx          009999996              1PALMER                   SMITH                                          9876543210009 MUNDALE WAY WEST                                                           MEXXXXX             XX38135      USA
xxxx     xxxx14        47xxx          009999996              2PALMER                   REBECCA                                        9876543210009 MUNDALE WAY WEST                                                           MEXXXXX             XX38135      USA
xxxx     xxxx14        47xxx          009999996              3SAL                      MIS                                            9876543210009 MUNDALE WAY WEST                                                           MXXXXXX             XX38135      USA
xxxx     xxxx14        47xxx          009999996              3PALMER                   JAMES                                          9876543210009 MUNDALE WAY WEST                                                           MXXXXXX             XX38135      USA

Appreciate your help !
# 2  
Old 03-27-2015
I think you should show us what have you tried so far and what is the problem with the approach
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract batch based on condition

HI, I have a file as mentioned below. Here one batch is for one user id.Batch starts from |T row and ends at .T row. I want to create a new file by reading this file. The condition is for record 10(position 1-2), if position 3 to position 17 is 0 then delete the entire batch and write into the new... (9 Replies)
Discussion started by: abhi.mit32
9 Replies

2. UNIX for Dummies Questions & Answers

Condition based on Timestamp (Date/Time based) from logfile (Epoch seconds)

Below is the sample logfile: Userids Date Time acb Checkout time: 2013-11-20 17:00 axy Checkout time: 2013-11-22 12:00 der Checkout time: 2013-11-17 17:00 xyz Checkout time: 2013-11-19 16:00 ddd Checkout time: 2013-11-21 16:00 aaa Checkout... (9 Replies)
Discussion started by: asjaiswal
9 Replies

3. Shell Programming and Scripting

extracting lines based on condition and copy to another file

hi i have an input file that contains some thing like this aaa acc aa abc1 1232 aaa abc2.... poo awq aa abc1 aaa aaa abc2 bbb bcc bb abc1 3214 bbb abc3.... bab bbc bz abc1 3214 bbb abc3.... vvv ssa as abc1 o09 aaa abc4.... azx aaq aa abc1 900 aqq abc19.... aaa aa aaaa abc1 899 aa... (8 Replies)
Discussion started by: anurupa777
8 Replies

4. Shell Programming and Scripting

How can I change file value based on condition

Hi, Gurus, I got a problem to resolve following issue: I have one file file1as following: start_dt=2010-01-01 12:00:02 start_dt=2011-01-01 09:00:02 start_dt=2009-01-01 11:00:02I have another file file2 as following: title1, 2010-01-03 10:00:02 title2, 2011-01-04 11:00:02 title3,... (5 Replies)
Discussion started by: ken002
5 Replies

5. Shell Programming and Scripting

Copy file to two folders with condition

Hello! Please, help me write this simple script using bash scripting. Task: In Folder1 I have files: name1.txt, name2.txt, name3.txt .. etc In Folder2 may located such files: name1.txt, name2.txt .. etc In Folder3 may located files like: name1.txt_abc{some_symbols}_vxz,... (6 Replies)
Discussion started by: optik77
6 Replies

6. Shell Programming and Scripting

Comment based on a condition

I want to comment 2 lines based on a condition. If THEN occurs immediately after WHEN then i have to comment both the lunes For example : $cat file1.txt CASE WHEN THEN 1 WHEN c1= 'I' AND c2= '0' THEN 2 So in this example i want to... (2 Replies)
Discussion started by: ashwin3086
2 Replies

7. Shell Programming and Scripting

Condition based concatenation.

Hello, I am looking for concatenating the lines based on conditions. Below are the contents of the file: Infile: ----- Test1.PO_Itm COLUMN GAC_DT. Test1.PO_Itm COLUMN (PRODTCD ,PLNTCD). Test1.PO_Itm COLUMN PLNTCD. Test1.PO_Itm COLUMN ACTVIND. Test2.RgnToTerrtryGPI COLUMN... (3 Replies)
Discussion started by: indrajit_u
3 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

transpose based on condition

Hi, I have the oracle table coulns in an order like date, state1, state2....state9 and i need to prepare data from the script output for loading in to this table The script is #!/bin/ksh /usr/xpg4/bin/awk -F"-" '{print $2,$4}' /aemu/ErrorLogs/data/MissingCGIcount.txt |... (5 Replies)
Discussion started by: aemunathan
5 Replies

10. Shell Programming and Scripting

How to search then remove based on condition

Folks; I'm trying to write a script to scan through a directory tree then for each file it finds, it run a command line tool, then if the results include the word "DONE", it removes the file. In more details; i have a Linux directory tree such as "/opt/grid/1022/store" I'm trying to write a... (6 Replies)
Discussion started by: Katkota
6 Replies
Login or Register to Ask a Question