LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-30-2010, 09:23 AM   #1
sqn
Member
 
Registered: Apr 2002
Distribution: Ubuntu, Arch, freeBSD, Slackware
Posts: 210

Rep: Reputation: 30
Question sed substitute everything until character


Hi all,

I have the following file:
Code:
1 line
...
49 test test=AA:AA:AA:AA:AA=0
I need to substitute on the line number 49, all text until =.
I have used the following, but with no actual result.
sed -re '49s/^.+\=//' file
and
sed -e '49s/.*[=]//' file
 
Old 03-30-2010, 09:27 AM   #2
PMP
Member
 
Registered: Apr 2009
Location: ~
Distribution: RHEL, Fedora
Posts: 381

Rep: Reputation: 58
Code:
echo "49 test test=AA:AA:AA:AA:AA=0"  | sed -e 's/^.\+\=//'
 
Old 03-30-2010, 09:32 AM   #3
sqn
Member
 
Registered: Apr 2002
Distribution: Ubuntu, Arch, freeBSD, Slackware
Posts: 210

Original Poster
Rep: Reputation: 30
echo "49 test test=AA:AA:AA:AA:AA=0" | sed -e 's/^.\+\=//'
0

It's no good. the resuls should be: =AA:AA:AA:AA:AA=0
 
Old 03-30-2010, 09:54 AM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
You should tell to match any number of non-"=" characters. This brings to the shortest match (that is the first "=" encountered terminates the matching string).
Code:
sed '49s/[^=]*//' file

Last edited by colucix; 03-30-2010 at 09:58 AM. Reason: Reviewed explanation to avoid confusion.
 
1 members found this post helpful.
Old 03-30-2010, 10:11 AM   #5
sqn
Member
 
Registered: Apr 2002
Distribution: Ubuntu, Arch, freeBSD, Slackware
Posts: 210

Original Poster
Rep: Reputation: 30
thx man , thx a lot
 
Old 03-30-2010, 10:27 AM   #6
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
You're welcome!
 
  


Reply



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
[SOLVED] SED - substitute a word only in a certain line carolflb Linux - Newbie 3 02-02-2010 09:30 AM
Replace 2nd to last Character with SED elproducto Programming 5 03-31-2009 12:41 PM
HP-UX newline character with sed jhwilliams Other *NIX 8 08-06-2007 05:13 PM
Sed substitute for my username? camaroblue87 Linux - Newbie 1 04-29-2006 11:07 AM
Insert character into a line with sed? & variables in sed? jago25_98 Programming 5 03-11-2004 06:12 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:09 AM.

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
Open Source Consulting | Domain Registration