Hi,
I have a problem to concatenate the lines based on number of delimiters (if the delimiter count is 9 then concatenate all the fields & remove the new line char bw delimiters and then write the following data into second line) in a file.
my input file content is
Title| ID| Owner| Estimate| Project| Complexity| Done| Feature Group|
Sprint|
RR - Bug in m_tgt_fact_org_hierarchy mapping| D-04980| fgfggf
Sejhh| 5.00| 2012 BI Project| | | 1.3 Ratings Reporting| Sprint 10
(10 -23 May)|
Intermediate results reports for US banks -Sprint1| B-49625| fhgh
fgh| 8.00| 2012 BI Project| | | 3.6 FI-RACE| Sprint 10 (10 -23 May)|
and expecting the output as follows:
Title| ID| Owner| Estimate| Project| Complexity| Done| Feature Group|Sprint|
RR - Bug in m_tgt_fact_org_hierarchy mapping| D-04980| fgfggfSejhh| 5.00| 2012 BI Project| | | 1.3 Ratings Reporting| Sprint 10 (10 -23 May)|
Intermediate results reports for US banks -Sprint1| B-49625| fhgh fgh| 8.00| 2012 BI Project| | | 3.6 FI-RACE| Sprint 10 (10 -23 May)|
I would really appreciate your help on this problem.
[mute@geek ~/temp/bi.infa]$ cat script
#!/usr/bin/awk -f
BEGIN { FS=OFS="|"; RS=""; cols=9 }
{
gsub(/\n/, "")
for (i=1;i<NF;i++) {
printf("%s%s",$i,++p==cols?OFS ORS:OFS)
if (p==cols) { p=0; }
}
}
[mute@geek ~/temp/bi.infa]$ ./script input
Title| ID| Owner| Estimate| Project| Complexity| Done| Feature Group|Sprint|
RR - Bug in m_tgt_fact_org_hierarchy mapping| D-04980| fgfggfSejhh| 5.00| 2012 BI Project| | | 1.3 Ratings Reporting| Sprint 10(10 -23 May)|
Intermediate results reports for US banks -Sprint1| B-49625| fhghfgh| 8.00| 2012 BI Project| | | 3.6 FI-RACE| Sprint 10 (10 -23 May)|
edit: ah. it seems newlines should be replaced with spaces in some instances? I understand after "Sprint 10", but "fgfggf Sejhh" and "fhgh fgh" seems to differ. should they both have newline replaced by space?
Alternatively try:
awk '{while(NF<10 && getline p)$0=$0p}1' FS=\| OFS=\| infile
1 Like
derrp. my avoidance of getline bit me. i was also anticipating concating two lines may make NF>10
birei
May 15, 2012, 1:02pm
5
Hi bi.infa,
One way using perl:
$ cat infile
Title| ID| Owner| Estimate| Project| Complexity| Done| Feature Group|
Sprint|
RR - Bug in m_tgt_fact_org_hierarchy mapping| D-04980| fgfggf
Sejhh| 5.00| 2012 BI Project| | | 1.3 Ratings Reporting| Sprint 10
(10 -23 May)|
Intermediate results reports for US banks -Sprint1| B-49625| fhgh
fgh| 8.00| 2012 BI Project| | | 3.6 FI-RACE| Sprint 10 (10 -23 May)|
$ perl -ne 'BEGIN { $/ = q[|] } s/\n//g; print $_, $. % 9 == 0 ? "\n" : ""' infile
Title| ID| Owner| Estimate| Project| Complexity| Done| Feature Group|Sprint|
RR - Bug in m_tgt_fact_org_hierarchy mapping| D-04980| fgfggfSejhh| 5.00| 2012 BI Project| | | 1.3 Ratings Reporting| Sprint 10(10 -23 May)|
Intermediate results reports for US banks -Sprint1| B-49625| fhghfgh| 8.00| 2012 BI Project| | | 3.6 FI-RACE| Sprint 10 (10 -23 May)|