LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-05-2010, 07:02 AM   #1
carolflb
Member
 
Registered: Oct 2009
Posts: 40

Rep: Reputation: 15
SED - substitution


Hi all,

I'm having a problem by substituting part of this sentence that is save in 'file':

inp1.inTicks_vl(ch_inTicks_vl);

I use the following SED command:

sed -i 's/[^ ]*\([0-9]*\).inTicks_vl([^ ]*);/inTicks_vl\1/' file


so that the sentence looks like this at the end:

inTicks_vl1

I want to move the number, that is part of the first name in the sentence, to the end of the second name in the sentence and erase all the rest.

But what I get with my command is:

inTicks_vl


so, I believe the command is not recognising that the first name is composed by letters and than by a number... [^ ]* is reading everything and [0-9]* doesn't find anything left...

Would somebody know how to solve this problem? The first name, which has a number at the end, can have random characters...
 
Old 02-05-2010, 07:34 AM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
In sed, awk and grep, use .* to match zero or more of any characters. The asterisk matches zero or more of the preceding character. Not zero or more characters. If you want to match a literal period in the LHS, then use "\.".

----

On the first reading, I didn't pick up on a space. It's better to put sed code in code blocks.
Code:
echo 'inp1.inTicks_vl(ch_inTicks_vl);' | sed 's/^[^ ]*\([[:digit:]]\)\.inTicks_vl[^ ]*/inTicks_v1\1/'
inTicks_v11
The ^ outside square brackets matches the beginning of a line.

Last edited by jschiwal; 02-05-2010 at 07:39 AM.
 
1 members found this post helpful.
Old 02-05-2010, 08:02 AM   #3
carolflb
Member
 
Registered: Oct 2009
Posts: 40

Original Poster
Rep: Reputation: 15
Hi jschiwal,

thanks a lot for the explanation. It helped a lot. I just wanted to ask one more thing:

is [[:digit:]] the same thing as [0-9]? Which is the difference?
 
Old 02-05-2010, 08:16 AM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
They are the same.

There is a complete list of the definitions here:
http://tldp.org/LDP/abs/html/x16608.html
 
1 members found this post helpful.
Old 02-05-2010, 08:22 AM   #5
carolflb
Member
 
Registered: Oct 2009
Posts: 40

Original Poster
Rep: Reputation: 15
Thanks for the link pixellany
 
Old 02-06-2010, 01:20 AM   #6
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
There is also a "regex (7)" manpage as well.
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems with a substitution using sed wtaicken Programming 4 12-15-2008 05:04 AM
variable substitution in sed gaynut Programming 1 07-14-2008 08:38 AM
sed substitution with p flag 7stud Linux - Newbie 2 03-03-2007 05:15 AM
Command substitution and sed daYz Linux - General 9 11-04-2006 02:15 AM
sed substitution conditional frostillicus Linux - Newbie 3 04-17-2005 01:36 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:54 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