On Friday 25 May 2012 22:32, J.O. Aho conveyed the following to
alt.linux...
> On 25/05/12 22:01,
rvae...@gmail.com wrote:
>
>> I have a file that doesn't have a field delimiter between the columns
>> and I want to add a colon between each column. I can identify the
>> columns by hard coding the range: such as "col1 to col 10" "col11 to
>> col24" etc...
>>
>> I am stuck.
>
> I'm assuming you have a space between the columns, [...
A space is a field separator too. From what he says, his file is simply
comprised of strings of characters.
> ...] then you could run the following:
>
> sed 's/ /:/g' -i filename
>
> before you run that one, you may want to test and see it give the
> result you want by not using the -i option:
>
> sed 's/ /:/g' filename
A solution would be to use /bin/cut with the "-c" option, given that he
knows the ranges of characters, and to then create a file with a proper
field separator from that.
The problem is most likely going to be that his fields have variable
lengths, so that he can't just cut up the records - i.e. the newline-
delimited strings - into equally sized slices. That makes it harder to
automate this procedure by way of a script.
The OP would probably get more specialized help in comp.unix.shell -
where all the scripting gurus live :p - but he will either way need to
provide more information, such as the number of fields he wishes to
define and whether these fields are of variable length. I'm no expert
on awk, but I think awk /might/ possibly provide for an easier way to do
this than pure Bourne shell code.
It is also going to be tricky in that, if there is a way to automate
this by way of a loop - i.e. reiteratively insert a field separator
character into each string until the end of the record - then one must
also keep into account that with every insertion, the number of
characters in the record increases, because field separator characters
are characters too. So the positioning of the insertion point will
always be off by 1 against the previous iteration.
As stated higher up, OP needs to provide more information.
--
= Aragorn =
(registered GNU/Linux user #223157)