Well, it looks like I'm late to the party but...
Are the fields tab-delimited, or whitespace-delimited in some other way that's different from the spaces inside the fields? Strings of 2 or more spaces, for example?
If there's some way to clearly define a delimiter,
awk would probably be a better tool to use. If the delimiters are tabs, for example:
Code:
awk 'BEGIN{ FS=OFS="\t" } { gsub(/[ ]/,"\t",$3) ; print }' file
The
FS setting splits the file into fields based on tabs, then the
gsub function replaces all spaces inside field3 with tabs, then the resulting line is printed, with
OFS delimiters (defined to be the same as FS) added back between fields.
If you have some other clear pattern for fields, you should be able to add it to the FS instead. For 2+ spaces, for example, you could replace the
BEGIN section above with this:
Code:
BEGIN{ FS="[ ][ ]+" ; OFS=" " }
( Unfortunately OFS can only contain a literal string value, so you have to set it separately when FS is a complex regex. AFAIK, you can't preserve the original field separators in awk, at least not without writing up a custom line parser ).
Otherwise, if we actually need to actually match the exact pattern of content, a sed solution like the one above would probably be a better choice.