Solved

SED command

Posted on 2004-09-21
12
345 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
  • 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
 

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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

rdate is a Linux command and the network time protocol for immediate date and time setup from another machine. The clocks are synchronized by entering rdate with the -s switch (command without switch just checks the time but does not set anything). …
How many times have you wanted to quickly do the same thing to a list but found yourself typing it again and again? I first figured out a small time saver with the up arrow to recall the last command but that can only get you so far if you have a bi…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

910 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now