![]() |
|
|
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 |
| need for loop to include fields as one line | prkfriryce | Shell Programming and Scripting | 8 | 03-23-2007 12:49 PM |
| fill a NIL into the blank field | happyv | Shell Programming and Scripting | 8 | 03-23-2007 04:49 AM |
| field separator as regexp | Abhishek Ghose | Shell Programming and Scripting | 2 | 02-15-2006 08:49 PM |
| awk: How to check if field is blank? | yongho | Shell Programming and Scripting | 7 | 06-09-2005 12:35 PM |
| How do I specify tab as field separator for sort? | SSteve | UNIX for Dummies Questions & Answers | 8 | 04-26-2005 05:39 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
how to include field separator if there are blank fields?
Hi,
I have the following data in the format as shown (note: there are more than 1 blank spaces between each field and the spaces are not uniform, meaning there can be one blank space between field1 and field2 and 3 spaces between field3 and field4, in this example, # are the spaces in between the fields): ________________________________________ num1a###num2a#num3a#####num4a##num5a num1b###num2b##########num4b####### #######num2c#num3c#####num4c##num5c #######num2d#num3d#####num4d##num5d num1e###num2e#num3e#####num4e##num5e num1f########################num5f ________________________________________ i need to include ; as the field delimiter and the required output is: ________________________________________ num1a;num2a;num3a;num4a;num5a num1b;num2b;;num4b; ;num2c;num3c;num4c;num5c ;num2d;num3d;num4d;num5d num1e;num2e;num3e;num4e;num5e num1f;;;;num5f ________________________________________ I tried using sed -e 's/ */;/g' but it will take consecutive blank fields as one blank field. Can anyone help? Last edited by ReV; 07-12-2005 at 08:45 AM.. |
|
||||
|
Quote:
num1f;;;;num5f is my required output. But when I use sed -e 's/ */;/g', my output is: num1f;num5f I hope I am clear with my description ![]() |
|
||||
|
Hi,
No, I only need one ; in between each field. But however, there can be one space or 2 spaces in between 2 fields. input: field1[space][space][space]field2[space][space]field3[space]field4 field1[space][space][space]emptyfield[space][space]emptyfield[space]field4 required output: field1;field2;field3;field4 field1;;;field4 but from the script that I have tried, I get: field1;field2;field3;field4 field1;field4 |
|
|||||
|
Quote:
what's the difference between '[space]' and 'emptyfield'? |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|