LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   Insert character by using sed/awk (http://www.linuxquestions.org/questions/linux-general-1/insert-character-by-using-sed-awk-543342/)

manish_meet_in 04-04-2007 01: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.

Thanks
Manish

homey 04-04-2007 05:58 PM

Here are a couple of nice sites on sed.
http://sed.sourceforge.net/sed1line.txt
http://www.grymoire.com/Unix/Sed.html#uh-8

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

wjevans_7d1@yahoo.co 04-04-2007 06:01 PM

First, do this:

Code:

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 12:19 PM

Thanks for the prompt reply.

I managed to resolved by awk command with substr function.

Thanks once again.

Manish


All times are GMT -5. The time now is 10:42 PM.