-   Linux - General (
-   -   Insert character by using sed/awk (

manish_meet_in 04-04-2007 02:55 PM

Insert character by using sed/awk
Hi Guys,

I need a help that how can i insert character/digit in line by line.

I want to add 3 numeric before 34th character, 3 character after 52, 1 character after 59th and 1 character after 75th.

Can you guide me how i can write a script/command
by using sed/awk.


homey 04-04-2007 06:58 PM

Here are a couple of nice sites on sed.

Here are a couple of examples to get you started.

# Add a word after the fifth character
sed 's/./&mudd/5' file.txt

# Add a word before the fifth character
sed 's/./mudd&/5' file.txt 04-04-2007 07:01 PM

First, do this:


man sed
man awk

If you end up being able to do this with sed, and avoid awk, it will go faster.

But read those two man pages.

Then start with a simpler problem than your final one. Dink with it until it works. Then add complexity until you have what you want.

If, along the way, you have a detailed question about why what you wrote doesn't work, this is a really good way to ask about it. But post all the details, including your sed or awk command, your input data, your output data, and any error message.

Good luck.

manish_meet_in 04-05-2007 01:19 PM

Thanks for the prompt reply.

I managed to resolved by awk command with substr function.

Thanks once again.


All times are GMT -5. The time now is 01:28 AM.