LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux > Linux - General
User Name
Password
Linux - General This 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

Tags used in this thread
Popular LQ Tags , ,

Reply
 
Thread Tools
Old 07-19-2009, 10:18 AM   #1
the_gripmaster
Member
 
Registered: Jul 2004
Location: Dhaka, Bangladesh
Distribution: openSUSE 11, RHEL 5.x, CentOS 5.x, OpenSolaris
Posts: 180
Thanked: 0
Question Help: Sed trick


[Log in to get rid of this advertisement]
I have a sample file:

Code:
           
AA019  120    988    102
BB 12  120    988    102
CC022  120    988    102
DD 25  120    988    102
EE     120    988    102
FF 21  120    988    102
GG     120    988    102
HH011  120    988    102
II     120    988    102
JJ 54  120    988    102
            ^
        more 4 space character in this column
I need to insert 4 spaces at the position indicated of every line. How can this be done?
the_gripmaster is offline  
Tag This Post , ,
Reply With Quote
Old 07-19-2009, 10:29 AM   #2
jschiwal
Moderator
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 12,877
Thanked: 232
You need four spaces inserted after the 12th character?

Code:
sed 's/\(.\{12\}\)\(.*\)/\1    \2/' sample.txt

Last edited by jschiwal; 07-19-2009 at 11:21 AM.. Reason: removed -e option from command.
jschiwal is offline     Reply With Quote
Thanked by:
Old 07-19-2009, 11:03 AM   #3
the_gripmaster
Member
 
Registered: Jul 2004
Location: Dhaka, Bangladesh
Distribution: openSUSE 11, RHEL 5.x, CentOS 5.x, OpenSolaris
Posts: 180
Thanked: 0

Original Poster
Quote:
Originally Posted by jschiwal View Post
You need four spaces inserted after the 12th character?

Code:
sed -e 's/\(.\{12\}\)\(.*\)/\1    \2/' sample.txt
Yup, you got it right. Thanks a lot.
the_gripmaster is offline     Reply With Quote

Reply

Bookmarks


Thread Tools

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: a little vi trick LXer Syndicated Linux News 0 04-29-2009 04:40 AM
vim :gui trick and undo-trick dazdaz Linux - Software 3 09-10-2007 03:45 PM
!(last command) trick? belorion Linux - General 5 07-03-2005 02:01 PM
Insert character into a line with sed? & variables in sed? jago25_98 Programming 5 03-11-2004 07:12 AM
How to trick a router Citizen Bleys Linux - Networking 4 01-31-2002 02:09 PM


All times are GMT -5. The time now is 11:29 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
RSS2  LQ Podcast
RSS2  LQ Radio
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration