Operating System - HP-UX
1847884 Members
5288 Online
104021 Solutions
New Discussion

Re: sed question: insert blanks or a string at defined position

 
SOLVED
Go to solution
Klaube
New Member

sed question: insert blanks or a string at defined position

Hi,
i want to insert two blanks after column 8 in all lines of a file. with awk no problem, but is it possible with sed? thx, Ivo
5 REPLIES 5
Roberto Polli
Trusted Contributor

Re: sed question: insert blanks or a string at defined position

for managing columns awk is better. with sed it's an harder work and could bear to prblems not easy to manage. If column 8 has particular form maybe can be easy.
With perl you can use printf and format which are built in function to print formatted output.
Pax, r.

Rodney Hills
Honored Contributor
Solution

Re: sed question: insert blanks or a string at defined position

If you really need to use "sed", then-

sed -e 's/^.\{8\}/& /'

HTH

-- Rod Hills
There be dragons...
Hein van den Heuvel
Honored Contributor

Re: sed question: insert blanks or a string at defined position

If you really want to use sed then you could for example do:


sed -e 's/./&test/8' your-input > your-output

This says:

for every line,
substitute the '9'th match (s///9)
for 'any char' (.)
by 'the match' (&)
and the word 'test' (or whatever else you like to be there).

Hein.



Klaube
New Member

Re: sed question: insert blanks or a string at defined position

Thx to all, Roberto's hint solved my problem in the best way.
Klaube
New Member

Re: sed question: insert blanks or a string at defined position

Sorry, not Roberto's hint, but Rodney's!