Solved

SED command

Posted on 2004-09-21
12
357 Views
Last Modified: 2010-04-20
Hi,

When I run this:

echo 1_2_spell.xml | sed 's/\([^\_]*\)\_\([^\_]*\.xml\)/\1.\2/'

I got the result :

1_2.spell.xml

How do I change the sed command switches to make it come out with:

1.2_spell.xml

instead?

Thanks.
CM
0
Comment
Question by:hocheeming
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
12 Comments
 
LVL 11

Expert Comment

by:avizit
ID: 12119960
echo 1_2_spell.xml | sed 's/\([^\_]*\)\_\([^\_]*\)\_\([^\_\.]*\)\.xml/\1.\2\_\3\.xml/'


seems to work
0
 
LVL 22

Expert Comment

by:pjedmond
ID: 12138921
Not sure what you are trying to do here?

But this works:

echo 1_2_spell.xml | sed 's/_/\1./'

...perhaps a more comprehensive example of the stream and manipulation required would be helpful?...or are we going for an obfusication award?

0
 
LVL 22

Expert Comment

by:pjedmond
ID: 12138945
..or even:

echo 1_2_spell.xml | sed 's/_/./'

as long as you don't stipulat the g (global obtion, only the first _ will be substituted!
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:hocheeming
ID: 12139180
How can I make a check in the characters between the "_" to be numeric?

For exp:

1_2_spell.xml convert 1.2_spell.xml

but for

1700_command_spell.xml (ignore: dun convert as "command" is non numeric)

Thanks.
0
 
LVL 11

Expert Comment

by:avizit
ID: 12139620
check for numeric as  

[0-9]+
0
 

Expert Comment

by:dReichel
ID: 12140767
echo 12.34_Abc.xml
echo 12.34_Abc.xml | sed -e 's/\([0-9]\+\)\.\([0-9]\+\)_\([^0-9]\+\)\.xml/\1_\2.\3.xml/'
0
 

Author Comment

by:hocheeming
ID: 12196443
It gives :

12_34.Abc.xml

I need:

12.34_Abc.xml

Please advise.

Thanks.
CM
0
 

Accepted Solution

by:
dReichel earned 50 total points
ID: 12253381
Oh - sorry :)

echo 12_34.Abc.xml
echo 12_34.Abc.xml | sed -e 's/\([0-9]\+\)_\([0-9]\+\)\.\([^0-9]\+\)\.xml/\1.\2_\3.xml/'

I tested it and it does produce

12.34_Abc.xml

Going back to your original question, the above script will transform 1_2_spell.xml to 1.2_spell.xml  Hopefully it will reject unwanted matches.
0
 
LVL 22

Expert Comment

by:pjedmond
ID: 13088999
I would have thought that my solution and that of avizit also did what was required. The check for numbers was an additional insight.

Anyway - your call:)
0

Featured Post

Containers & Docker to Create a Powerful Team

Containers are an incredibly powerful technology that can provide you and/or your engineering team with huge productivity gains. Using containers, you can deploy, back up, replicate, and move apps and their dependencies quickly and easily.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question