LinuxQuestions.org
Help answer threads with 0 replies.
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 07-19-2009, 10:18 AM   #1
the_gripmaster
Member
 
Registered: Jul 2004
Location: VIC, Australia
Distribution: RHEL, CentOS, Ubuntu Server, Ubuntu
Posts: 362

Rep: Reputation: 38
Question Help: Sed trick


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?
 
Old 07-19-2009, 10:29 AM   #2
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655
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.
 
Old 07-19-2009, 11:03 AM   #3
the_gripmaster
Member
 
Registered: Jul 2004
Location: VIC, Australia
Distribution: RHEL, CentOS, Ubuntu Server, Ubuntu
Posts: 362

Original Poster
Rep: Reputation: 38
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.
 
  


Reply

Tags
edit, sed, text


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
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 04:26 PM.

Main Menu
Advertisement
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