Append line that does not contain pipe to it previous line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Append line that does not contain pipe to it previous line
# 1  
Old 11-07-2008
Append line that does not contain pipe to it previous line

Hi All,

I have a file which contains data as below
When we see no pipe character in the line. append those lines to the previous line with pipe character till we get the next line with pipe character with ~(concat with ~)
Input file looks like:
1080530944|001|john.l.bonner|Acknowledge|CN Approved-Implement Change to Meet Target Effectivity Date|2007/06/20-18:41:49:735|2007/06/28-16:25:48:662|
1080530944|001|larry.d.groves|Acknowledge|CN Approved-Implement Change to Meet Target Effectivity Date|2007/06/20-18:41:49:931|2007/06/21-20:13:41:581|
1080530944|001|michael.g.krumheuer|Acknowledge|CN Approved-Implement Change to Meet Target Effectivity Date|2007/06/20-18:41:50:099|2007/06/25-14:08:22:330|
1080530944|001|paul.j.frederick|Acknowledge|CN Approved-Implement Change to Meet Target Effectivity Date|2007/06/20-18:41:50:234|2007/06/22-13:14:19:439|
1080530944|001|rich.jester|Acknowledge|CN Approved-Implement Change to Meet Target Effectivity Date|2007/06/20-18:41:50:355|2007/06/21-14:25:43:604|
1080530944|001|robert.g.campbell|Acknowledge|CN Approved-Implement Change to Meet Target Effectivity Date|2007/06/20-18:41:50:470|2007/08/30-15:31:49:127|
1080530944|001|douglas.h.markwood|Reassigned|Monitor & Control Change Notice in the Holding Area|2007/06/20-18:42:01:259|2007/06/20-18:45:42:324|s b295 Please monitor this change and update the ITA with any/all completion dates.
When you have completed the changes and it has been implemented,
Complete this task on your show list and "reassign" the next task back to me.
E-mail me with the Actual Effectively and Completion dates. Thanks Doug M.
1080530944|001|robert.g.campbell|Complete (See Comments)|Monitor & Control Change Notice in the Holding Area|2007/06/20-18:45:42:536|2007/08/30-15:38:28:067|ok


Output File should be:

1080530944|001|john.l.bonner|Acknowledge|CN Approved-Implement Change to Meet Target Effectivity Date|2007/06/20-18:41:49:735|2007/06/28-16:25:48:662|
1080530944|001|larry.d.groves|Acknowledge|CN Approved-Implement Change to Meet Target Effectivity Date|2007/06/20-18:41:49:931|2007/06/21-20:13:41:581|
1080530944|001|michael.g.krumheuer|Acknowledge|CN Approved-Implement Change to Meet Target Effectivity Date|2007/06/20-18:41:50:099|2007/06/25-14:08:22:330|
1080530944|001|paul.j.frederick|Acknowledge|CN Approved-Implement Change to Meet Target Effectivity Date|2007/06/20-18:41:50:234|2007/06/22-13:14:19:439|
1080530944|001|rich.jester|Acknowledge|CN Approved-Implement Change to Meet Target Effectivity Date|2007/06/20-18:41:50:355|2007/06/21-14:25:43:604|
1080530944|001|robert.g.campbell|Acknowledge|CN Approved-Implement Change to Meet Target Effectivity Date|2007/06/20-18:41:50:470|2007/08/30-15:31:49:127|
1080530944|001|douglas.h.markwood|Reassigned|Monitor & Control Change Notice in the Holding Area|2007/06/20-18:42:01:259|2007/06/20-18:45:42:324|s b295 Please monitor this change and update the ITA with any/all completion dates.~When you have completed the changes and it has been implemented,~Complete this task on your show list and "reassign" the next task back to me.~E-mail me with the Actual Effectively and Completion dates. Thanks Doug M.
1080530944|001|robert.g.campbell|Complete (See Comments)|Monitor & Control Change Notice in the Holding Area|2007/06/20-18:45:42:536|2007/08/30-15:38:28:067|ok
# 2  
Old 11-07-2008
Use nawk or /usr/xpg4/bin/awk on Solaris:
Code:
awk 'END { print l }
{ l = l ? l (/\|/ ? RS : "~" ) $0 : $0 }
/\|/ && f { print l; l = f = 0 }
!/\|/ { f = 1 }' infile


Last edited by radoulov; 11-10-2008 at 04:20 AM..
# 3  
Old 11-07-2008
Great! Excellent. It worked.
However it missed out very few data. i did that manually.

thanks a lot for your help.
# 4  
Old 11-07-2008
Quote:
Originally Posted by ainuddin
However it missed out very few data.
Hm,
even after adding the END block (I've modified the initial code)?
# 5  
Old 11-10-2008
perl:

Code:
open FH,"<file";
while(<FH>){
	$t++;
	if(m/\|/){
		$arr[$t]=$_;
	}
	else{
		$t--;
		$arr[$t]=~s/\n//g;
		$arr[$t]=sprintf("%s~%s",$arr[$t],$_);
	}
	
}
close FH;
foreach(@arr){
	print;
}

# 6  
Old 11-11-2008
Hi Radouluv,Summer_cherry.

Thanks both of you it worked.

I am struggling to format the output with awk. i need a report file.

your help on this will be appreciated.


Fallowing is the input file that is pipe seperated.
is it possible to generated the report that is alligned left justifed as that of sample output.
I apprecitae your help on this.
InputFile:
Code:
108005555|001|christina.lipski||Submitter Signature|2005/05/09-19:16:19:021|2005/05/10-15:52:36:112| eSCR 10744 attachment in REF file
108005555|001|james.m.thompson|Unable to Complete (See Comments)|Initial Change Request Assessment|2005/05/09-19:16:21:794|2005/05/10-15:00:48:486|1 Christina Lipski
~In the body of the change request I cut and pasted Jim Lopez's comments. According to him, the inductance limit is already complete and the eSCR should have been describing a different request to change the process. Read the comment. The eSCR should probably be rejected and re-issued with the proper description. 
108005555|001|james.m.thompson||Submitter Signature|2005/05/10-15:00:25:440|2005/05/10-15:00:54:659|0 Mike,
~Do you agree that this eSCR should be reissued by the supplier AND that you should be the change owner?
108005555|001|super user|OK - See Comments|Read the comments and correct me if I'm wrong.|2005/05/10-15:00:27:109|2005/05/10-15:00:53:687| Auto-signoff for Advisor Participant "james.l.lopez" to remove from inbox.
108005555|001|super user|OK - See Comments|Read the comments and correct me if I'm wrong.|2005/05/10-15:00:27:187|2005/05/10-15:00:53:964| Auto-signoff for Advisor Participant "michael.s.thompson" to remove from inbox.
108005555|001|christina.lipski|Complete (See Comments)|Perform additional work on CR|2005/05/10-15:01:00:066|2005/05/10-15:20:26:144| CR cannot be completed. Please reject. 
108005555|001|james.m.thompson|Unable to Complete (See Comments)|Initial Change Request Assessment|2005/05/10-15:20:28:870|2005/05/10-15:52:11:597| eSCR that initiated this change request had wrong information. eSCR is rejected.

Output File Should look like
Code:
==================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================
USER                     ACTION TAKEN    ASSIGNMENT     TIMESTAMP IN    SIGNOFF DATE             COMMENTS  
==================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================
christina.lipski      Submitter Signature    2005/05/09-19:16:19:021   2005/05/10-15:52:36:112    eSCR 10744 attachment in REF file
james.m.thompson          Unable to Complete (See Comments) Initial Change Request Assessment  2005/05/09-19:16:21:794   2005/05/10-15:00:48:486   1 Christina Lipski~In the body of the change request I cut and pasted Jim Lopez's comments. According to him, the inductance limit is already complete and the eSCR should have been describing a different request to change the process. Read the comment. The eSCR should probably be rejected and re-issued with the proper description. 
james.m.thompson      Submitter Signature    2005/05/10-15:00:25:440   2005/05/10-15:00:54:659   0 Mike,~Do you agree that this eSCR should be reissued by the supplier AND that you should be the change owner?
super user                OK - See Comments   Read the comments and correct me if I'm wrong. 2005/05/10-15:00:27:109   2005/05/10-15:00:53:687    Auto-signoff for Advisor Participant "james.l.lopez" to remove from inbox.
super user                OK - See Comments   Read the comments and correct me if I'm wrong. 2005/05/10-15:00:27:187   2005/05/10-15:00:53:964    Auto-signoff for Advisor Participant "michael.s.thompson" to remove from inbox.
christina.lipski          Complete (See Comments)  Perform additional work on CR   2005/05/10-15:01:00:066   2005/05/10-15:20:26:144    CR cannot be completed. Please reject. 
james.m.thompson          Unable to Complete (See Comments) Initial Change Request Assessment  2005/05/10-15:20:28:870   2005/05/10-15:52:11:597    eSCR that initiated this change request had wrong information. eSCR is rejected.

I have tried the fallowing AWK script. did not help me with the correct format.

Last edited by radoulov; 11-11-2008 at 09:42 AM.. Reason: added code tags
# 7  
Old 11-11-2008
Did you try a tab separated fields?

Code:
 awk -F\| '$1=$1' OFS='\t' infile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove new line starting with a numeric value and append it to the previous line

Hi, i have a file with multiple entries. After some tests with sed i managed to get the file output as follows: lsn=X-LINK-IN0,apc=661:0,state=avail,avail/links=1/1, 00,2110597,2094790,0,81,529,75649011,56435363, lsn=TM1ITP1-AM1ITP1-LS,apc=500:0,state=avail,avail/links=1/1,... (5 Replies)
Discussion started by: nms
5 Replies

2. Shell Programming and Scripting

Issue while append to previous line

Hi, I have data as below. 36578019,005-923887317,UNMDL,20151230,2C3CCAAG4GH135448,L,TX,20160108,62,"030916 PPT TX AFF RPRT VALID AFF IN PDP WLL FWD TO RYAN ON 031116 CB1619 ",, 36580219,611-923785453,FC,20151209,ZACCJABT9FPC19274,L,TX,20160108,83,,,... (4 Replies)
Discussion started by: JSKOBS
4 Replies

3. UNIX for Dummies Questions & Answers

How to remove fields space and append next line to previous line.?

awk 'BEGIN{FS = "Ç"} NR == 1 {p = $0; next} NF > 1 {print p; p = $0} NF <= 1 {p = (p " " $0)} END {print p}' input.txt > output.txt This is what the input data file looks like with broken lines Code: 29863 Ç890000000 Ç543209911 ÇCHNGOHG Ç000000001 Ç055 ... (4 Replies)
Discussion started by: cumeh1624
4 Replies

4. Shell Programming and Scripting

Append next line to previous lines when NF is less than 0

Hi All, This is very urgent, I've a data file with 1.7 millions rows in the file and the delimiter is cedilla and I need to format the data in such a way that if the NF in the next row is less than 1, it will append that value to previous line. Any help will be appricated. Thanks,... (17 Replies)
Discussion started by: cumeh1624
17 Replies

5. Shell Programming and Scripting

Split a line and append pipe

I have a requirement like below 030150678 bos 00156 0500405612 23 23 i have split the above line based on position and append pipe to it 1-3 , 4-8, 9, 10-18,19-25,26-27 030|15067|8| .... so on i can't use cut because... (11 Replies)
Discussion started by: greenworld123
11 Replies

6. Shell Programming and Scripting

Append next line to previous line when one pattern not found

Hi, I need help for below scenario.I have a flat file which is having records seperated by delimiters which will represent each record for oracle table.My Control file will consider each line as one record for that table. Some of the lines are aligned in two/three lines so that records are... (4 Replies)
Discussion started by: kannansr621
4 Replies

7. Shell Programming and Scripting

Append specific lines to a previous line based on sequential search criteria

I'll try explain this as best I can. Let me know if it is not clear. I have large text files that contain data as such: 143593502 09-08-20 09:02:13 xxxxxxxxxxx xxxxxxxxxxx 09-08-20 09:02:11 N line 1 test line 2 test line 3 test 143593503 09-08-20 09:02:13... (3 Replies)
Discussion started by: jesse
3 Replies

8. Shell Programming and Scripting

Append each line to next previous line in a file

Hi all, Please help me in providing sample code to append the following 4 lines in one row. Input : A1/EXT "BAPBSC10/07B/00" 523 090530 0115 RXOCF-430 HY1711 1 EXTERNAL ALARM DOOR ALARM Output should be : A1/EXT "BAPBSC10/07B/00" 523 090530 0115 ... (8 Replies)
Discussion started by: sudhakaryadav
8 Replies

9. Shell Programming and Scripting

SED or AWK "append line to the previous line"

Hi, How can I remove the line beak in the following case if the line begin with the special char “;”? TEXT Text;text ;text Text;text;text I want to convert the text to: Text;text;text Text;text;text I have already tried to use... (31 Replies)
Discussion started by: research3
31 Replies

10. UNIX for Advanced & Expert Users

append the line with the previous if it not start with 1=

How to append the line with the previous if it not start with 1=. 1=ttt, 2=xxxxxx, 3=4545 44545, 4=66666, 1=ttt, 2=xxxxxx, 3=34434 3545, 4=66666, 5=ffffff 6=uuuuuuu, 7=ooooooo 1=ttt, 2=xxxxxx, 3=311343545, 4=66666 1=ttt, 2=xxxxxx, 5=XAXAXA, 7=FDFD (3 Replies)
Discussion started by: palsevlohit_123
3 Replies
Login or Register to Ask a Question