LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 04-04-2007, 01:55 PM   #1
manish_meet_in
Member
 
Registered: Apr 2006
Posts: 40

Rep: Reputation: 15
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
 
Old 04-04-2007, 05:58 PM   #2
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 56
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
 
Old 04-04-2007, 06:01 PM   #3
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 30
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.
 
Old 04-05-2007, 12:19 PM   #4
manish_meet_in
Member
 
Registered: Apr 2006
Posts: 40

Original Poster
Rep: Reputation: 15
Thanks for the prompt reply.

I managed to resolved by awk command with substr function.

Thanks once again.

Manish
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert after every nth character using sed DoDo1975 Linux - Software 2 01-17-2007 06:59 PM
How do I insert special character with alt? Meriadoc Linux - Newbie 5 05-17-2006 10:42 AM
Insert a special character with the keyboard? Schreiberling Linux - General 0 03-05-2006 09:09 AM
insert string with sed greg108 Programming 7 02-18-2005 01:11 PM
Insert character into a line with sed? & variables in sed? jago25_98 Programming 5 03-11-2004 06:12 AM


All times are GMT -5. The time now is 09:36 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration