?
Solved

SED command

Posted on 2004-09-21
12
Medium Priority
?
388 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
9 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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 200 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

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

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

Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
Fine Tune your automatic Updates for Ubuntu / Debian
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses
Course of the Month14 days, 9 hours left to enroll

839 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