rimss
June 7, 2006, 2:18pm
1
I need to check the count of pipes on each line of the data to make sure we 4 pipes if its less i need to keep adding the string to form a single line ( Need to join/ concat the below lines until i get the 4 pipes which is end of record ). This fields is basicall a memo where the user would have typed a small paragraph that needs to be joined into a single line.
Sample Broken Lines and data
-----------------------------
467|Computer Monitor|Purchase Prise $150
Best Price $100
Cheapest Price $75
[RIGHT]highest price $200|T| [/RIGHT]
Correct record would look like this
467|Computer Monitor|Purchase Prise $150 Best Price $100 Cheapest Price $75 highest price $200|T|
Thanks,
nawk -f rim.awk myFile.txt
rim.awk:
BEGIN {
FS=OFS="|"
FLDmax="4"
}
NF > FLDmax { print; next }
NF {
line=(line=="") ? $0 : line " " $0
if ( split(line, lineA, OFS) > FLDmax ) {
print line
line=""
}
}
rimss
June 7, 2006, 2:58pm
3
vgersh99 Thanks a lot for the quick response.
It worked but i am getting some blank / white spaces before each text in this case it looks like this
467|Computer Monitor|Purchase Prise $150 Best Price $100 Cheapest Price $75 highest price $200T|
Sorry i tried my best to paste it could not get it to appear here. Baically there are lot of spaces between each for eg
Purchase Prise $150 <SPACE SPACE SPACE > Best Price $100 <SPACE SPACE SPACE >Cheapest Price $75<SPACE SPACE SPACE >highest price $200|T|
Would be really great if i can get it as
467|Computer Monitor|Purchase Prise $150 Best Price $100 Cheapest Price $75 highest price $200|T|
Thanks for all your help
try the latest code - I've made some modifications.
Also when posting code and/or sample data files, pls use vB codes .
Pls post the exact input file using the the vB codes.
rimss
June 7, 2006, 3:10pm
5
Sorry dont see the latest code on your reply
BEGIN {
FS=OFS="|"
FLDmax="4"
}
function compressSpace(str) {
gsub(/[ ][ ]*/, " ", str)
return str
}
NF >= FLDmax { print compressSpace($0); next }
NF {
line=(line=="") ? $0 : line " " $0
if ( split(line, lineA, OFS) > FLDmax ) {
print compressSpace(line)
line=""
}
}
rimss
June 7, 2006, 3:17pm
7
vgersh99 - Thank you very much you made my day !!! Really appreciate your help on this.