![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| make multiple line containing a pattern into single line | VTAWKVT | Shell Programming and Scripting | 13 | 12-04-2008 06:40 PM |
| How to convert a single column into several rows and columns? | ashton_smith | UNIX for Dummies Questions & Answers | 5 | 05-24-2008 04:44 PM |
| script for a 3 line paragraph | invinzin21 | Shell Programming and Scripting | 2 | 12-18-2007 01:11 AM |
| SED or AWK: Appending a line Identifier that changes with paragraph? | selkirk | UNIX for Dummies Questions & Answers | 1 | 04-28-2007 02:03 AM |
| here-doc convert 2 script convert to single script? | yongho | Shell Programming and Scripting | 2 | 07-07-2005 04:14 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Convert a paragraph to single line
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 highest price $200|T| Correct record would look like this 467|Computer Monitor|Purchase Prise $150 Best Price $100 Cheapest Price $75 highest price $200|T| Thanks, |
|
||||
|
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 |
|
|||||
|
Code:
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=""
}
}
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|