|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
[Solved] Help correcting file with differing number of fields
Hi all, I have a tab separated file, and one of the fields is sub-delimited by colon. The problem is there can be zero to 4 colons within this field. When I try to change colons to tabs the result is a file with a differing number of fields. I want to go from: Code:
a:b:c:d:e a:b:c a:b:c:d:e a a:b:c:d:e To: Code:
a b c d e a b c . . a b c d e a . . . . a b c d e Any help is appreciated! Thanks |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
That seems to work perfectly!! Thanks so much.
|
|
#4
|
||||
|
||||
|
this works for n number of columns Code:
$ n=$(awk -F: 'NF>a{a=NF}END{print a}' input.txt);
$ awk -F: -v n="$n" '{for(i=1i<=n;i++)if($i=="")$i="."}NF==n{gsub(":"," ")}1' input.txt
a b c d e f g h i . .
a b c . . . . . . . .
a b c d e . . . . . .
a . . . . . . . . . .
a b c d e . . . . . .
a b c d e f g h i j k
$ cat a.txt
a:b:c:d:e:f:g:h:i
a:b:c
a:b:c:d:e
a
a:b:c:d:e
a:b:c:d:e:f:g:h:i:j:k |
| The Following User Says Thank You to itkamaraj For This Useful Post: | ||
torchij (11-19-2012) | ||
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
works great, thanks so much.
|
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| [Solved] using sed delete a line from csv file based on specific data in two separate fields | Chris Eagleson | UNIX for Dummies Questions & Answers | 2 | 10-10-2012 12:14 PM |
| separate the file according to the number of fields | ratheeshjulk | Shell Programming and Scripting | 3 | 08-16-2011 12:33 PM |
| Problem while counting number of fields in TAB delimited file | vikanna | UNIX for Advanced & Expert Users | 12 | 06-14-2011 02:50 AM |
| number of fields in a text file as a variable - perl | dynamax | Shell Programming and Scripting | 1 | 05-25-2011 03:15 AM |
| awk sed cut? to rearrange random number of fields into 3 fields | axo959 | Shell Programming and Scripting | 4 | 04-29-2009 04:18 AM |
|
|