Inserting a character in certain column
Aart Koelewijn
aart at mtack.xs4all.nl
Mon Feb 25 14:25:12 UTC 2008
On Mon, 25 Feb 2008 12:51:45 -0800, Szemerédy Gábor wrote:
> Aart Koelewijn wrote:
>> On Mon, 25 Feb 2008 08:24:40 -0800, Szemerédy Gábor wrote:
>>
>>
>>> Hello list!
>>> I need to insert a character in certain column in all rows of the file
>>> using vi.
>>> Please help
>>>
>>>
>> Has it to be vi? I would use awk for something like that.
>>
>> Aart
>>
>>
>>
> Thanks for your answer!
> No!Everything is OK for solving the problem.Can you give me a syntax?
> Gabor
something like "awk '{print $1, $2, [your char], $3, $4}' oldfile >
newfile". But this will only work if there is a column separator between
the columns like [TAB]. There is also a letter in this list telling you
how you could do it with vi. Another command which can be usefull for
such operations is sed, and off course perl lovers will use perl ;-)
Personally, when you are talking about columns like in a spreadsheet or
database output my first choice will usually be awk. If you are talking
about the Nth column in a text file, sed might be better and perl can be
used for anything. The vi solution is great if you only have to do it
once, I would prefer one off the other solutions if you have to change a
number off files.
For me sed, awk and perl are some off the pearls off *nix ;-)
Aart
More information about the ubuntu-users
mailing list